CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   HTML & CSS (http://www.codingforums.com/forumdisplay.php?f=13)
-   -   Perform maths function on number input (http://www.codingforums.com/showthread.php?t=286613)

zebra2188 01-29-2013 06:32 AM

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?

sunfighter 01-29-2013 03:22 PM

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.


All times are GMT +1. The time now is 09:38 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.