View Full Version : Javascript - adding imput box totals
novatron6
October 19th, 2004, 06:18 PM
<!-- message --> Hey All,
I need to simply add two or three imput fields on a online form I have and have the result show up in a "total" box, so that the user will be able to see the total from the numbers they enter, someone said I might be able to do this in javasciprt, any ideas or tutorials or links would be helpful! thanks!
doug
teiz77
October 20th, 2004, 08:14 AM
try this...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
<!--
function setTotal() {
input1 = eval(document.getElementById('input1').value);
input2 = eval(document.getElementById('input2').value);
total = input1 + input2;
document.getElementById('total').value = total;
}
-->
</script>
</head>
<body>
<form name="form1" id="form1" method="post" action="">
<p>input 1: <input name="input1" type="text" id="input1" /></p>
<p>input 2: <input name="input2" type="text" id="input2" /></p>
<p> </p>
<p>Total:<input name="total" type="text" id="total" /></p>
<p><input name="calculate" type="button" id="calculate" value="Calculate" onclick="javascript:setTotal();"/></p>
</form>
</body>
</html>
novatron6
October 20th, 2004, 11:35 AM
Thanks alot!
just what I was looking for!
doug
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.