Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    1
    Thanks
    0
    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?

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,770
    Thanks
    23
    Thanked 550 Times in 549 Posts
    Not pretty, but shows you what to do:
    Code:
    <!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>
    Did not check for numbers only.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •