Click to See Complete Forum and Search --> : Form Calculator


gildedsplinters
02-19-2003, 07:02 AM
I received help with this calculator for a form that I am building, and was wondering if there is anyway to build it without having to use the buttons to total the totals and subtotal. The address where the form is is http://www.arrowheadgloves.com/form.htm. Below is the code that i received from a helpful member of webdeveloper!

Any and all help will be appreciated!

<html>
<head>

<script language="javascript" type="text/javascript">
function add()
{
var one = document.test.value1.value;
var two = Number(one) * 60;
document.test.subtotal.value = two;
}
function add2()
{
if (document.test.value2.value != "")
{
var one2 = document.test.value2.value;
var two2 = Number(one2) * 72;
document.test.newsubtotal.value = two2;
}
}
function add3()
{
var one3 = document.test.subtotal.value;
var two3 = document.test.newsubtotal.value;
document.test.total.value = Number(one3) + Number(two3);
}
</script>

</head>
<body>

<form action="" name="test">
<input name="value1">+60 = <input name="subtotal"><br>
<input name="value2">+72 = <input name="newsubtotal"><br>
Total = <input name="total"><br>
<input type="button" onClick="add(); add2();" value="add">
<input type="button" onClick="add3();" value="total"><br>
</form>

</body>
</html>

khalidali63
02-19-2003, 09:30 AM
Yes it is possible,the point is you havenot mentioned what is the alternative for you.

for instance you can make it a link
change these 2 lines
<input name="button" type="button" onClick="add(); add2();" value="calculate">
<input name="button" type="button" onClick="add3();" value="calculate total">

to this

<a href="javascript:add(); add2();">Calculate</a>

<a href="javascript:add3();">Calculate</a>

Hope this helps

Khalid