I have an expense report type form that has an input asking for mileage. When a user types in a number, I’d like there to be an auto calculate sort of function that displays the amount they will be reimbursed.
For instance, if a user types in “65”, to the right of the input box would be “65 x $.555 = $36.08”.
JS is not my strong suit, but I know I’ll need to use a hidden div to display the JS generated text, and some code to make sure the “total” is rounded to 2 decimal places. Any ideas/suggestions?
Example
jQuery isn’t needed, but helpful.
toFixed method
parseFloat method
If you needed to do the rounding: