Skip to content
Advertisement

I’m trying to make a form based calculatorfor a business equation

I’m trying to create a form based calculator for a business equation which works out break-even return on ad spend.

The fucntion works, I’ve testred it through the console on Chrome. But this is ony when I set the variables to numbers, I’m struggling to use the data from the form to work it out.

I don’t know if using a form is right for this. The part I can’t figure out is linking the HTML form data to the JS variables.

JavaScript
JavaScript

Advertisement

Answer

Take in consideration:

  1. to get the value of any input use attribute .value
JavaScript

Add submit input to fire the function calculate()

JavaScript
  1. to get the returned value from a function you have to call it.
JavaScript

Note: event.preventDefault() prevent the form from reloading.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement