updated js function for advanced calculator, moved the stuff in the view since change wouldnt trigger