I am making a small calculator (just for JavaScript learning) and I have two input fields for fraction calculation:
- Field: numerator
- Field: denominator
And a button “Calculate fraction” which executes the function myFraction(numerator,denominator) when user clicks on it.
Is it possible to do the same without the Button?
I mean JavaScript should recognize that someone is making input and then calculate the fraction automatically.
You can hook into the onkeyup or onkeydown event handlers and call your function:
You’ll need to grab the values of the text boxes inside the myFraction() function and check to see if they’re blank before you output the fraction value to the screen though.