Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
01-29-2013, 06:32 AM #1
- Join Date
- Jan 2013
- Thanked 0 Times in 0 Posts
Perform maths function on number input
Hi im completely new to coding so forgive me for being a complete noob but Im looking for a script that will allow me to have 2 input boxes (one for grams of fat the other for grams of sugar) and on entry I need it to display the first amount divided by 300 and the second divided by 4 in two text boxes?
01-29-2013, 03:22 PM #2
- Join Date
- Jan 2011
- Thanked 522 Times in 521 Posts
Not pretty, but shows you what to do:
<!DOCTYPE html> <html> <head> <title>Title of the document</title> </head> <body> Enter grams of fat: <input type="text" id="fatin" onkeyup="
document.getElementById('fat').value = document.getElementById('fatin').value/300;"> This is a changed fat thing: <input id="fat"><br /> Enter grams of sugar: <input type="text" id="sugin" onkeyup="
document.getElementById('sugar').value = document.getElementById('sugin').value/4;"> This is a changed sugar thing: <input id="sugar"> </body> </html>