Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-29-2013, 06:32 AM   PM User | #1
zebra2188
New to the CF scene

 
Join Date: Jan 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
zebra2188 is an unknown quantity at this point
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?
zebra2188 is offline   Reply With Quote
Old 01-29-2013, 03:22 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,366
Thanks: 18
Thanked 348 Times in 347 Posts
sunfighter is on a distinguished road
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.
sunfighter is online now   Reply With Quote
Reply

Bookmarks

Tags
code, input, maths

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:27 AM.


Advertisement
Log in to turn off these ads.