Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to do client side adding of form fields before submission

Status
Not open for further replies.
Jan 19, 2003
34
US
If I have two fields on a form, and need to add them together and place the sum in another field in the form automatically so the user can see the total before submission, how would I do that?
 
Put an onchange event on the two boxes that calls a javascript function that adds the two values together and puts them into the third.

e.g.
<html>
<head>
<script language=&quot;javascript&quot;>
function addValues()
{
myForm.box3.value = myForm.box1.value*1 + myForm.box2.value*1;
}
</script>
</head>
<body>
<form id=&quot;myForm&quot;>
<input id=&quot;box1&quot; onchange=&quot;javascript:addValues();&quot; type=&quot;text&quot;>
<input id=&quot;box2&quot; onchange=&quot;javascript:addValues();&quot; type=&quot;text&quot;>
<input id=&quot;box3&quot; type=&quot;text&quot;>
</form>
</body>
</html>

Hope this helps,

Rob.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top