Click to See Complete Forum and Search --> : multiplying two fields


gildedsplinters
02-13-2003, 11:48 AM
I want to multiply two fields say X x a set value of $60.00. This would output to one field.

I then want to do this again but this time X x a set value of $72.00 to another field.

I then want a total field that the two results would be added up to a total. I am new to javascript and have downloaded and worked with a number of basic "calculators" but I just want these calculations.

Any and all help would be appreciated!

pyro
02-13-2003, 12:39 PM
This should do the trick for you.

<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"> &nbsp;
<input type="button" onClick="add3();" value="total"><br>
</form>

</body>
</html>