Please help!
I have a simple order form (code pasted below) and I am having trouble making the fields only allowing for 2 decimal places.
For instance, when I calculate 3 x .35 I get 1.049999999999999
Can anyone help, or please let me know what I'm doing wrong? I am a beginner at javascript and perhaps there is also a better way to calculate fields too.
Thanks very much!
Jon
--------------------
<html>
<head>
<title>Test Form</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function calcTotal(form){
StoreOrderForm.Total1.value = (eval(StoreOrderForm.Qty1.value) * eval(StoreOrderForm.Price1.value));
StoreOrderForm.Total2.value = (eval(StoreOrderForm.Qty2.value) * eval(StoreOrderForm.Price2.value));
StoreOrderForm.Subtotal.value = (eval(StoreOrderForm.Total1.value) + eval(StoreOrderForm.Total2.value));
}
// End -->
</script>
</head>
<body>
<form method="POST" name="StoreOrderForm" action="--WEBBOT-SELF--">
<!--webbot bot="SaveResults"
U-File=" S-Format="TEXT/CSV"
S-Label-Fields="TRUE" -->
Qty: <input type="text" name="Qty1" size="20" onChange="calcTotal(this.form)" value="0.00">
Price: <input type="text" name="Price1" size="20" onChange="calcTotal(this.form)" value="0.00">
Total: <input type="text" name="Total1" size="20" value="0.00" readonly><br>
Qty: <input type="text" name="Qty2" size="20" onChange="calcTotal(this.form)" value="0.00">
Price: <input type="text" name="Price2" size="20" onChange="calcTotal(this.form)" value="0.00">
Total: <input type="text" name="Total2" size="20" value="0.00" readonly>
<p><b>Total: </b> <input type="text" name="Subtotal" size="20" value="0.00" readonly></p>
<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
</body>
</html>
I have a simple order form (code pasted below) and I am having trouble making the fields only allowing for 2 decimal places.
For instance, when I calculate 3 x .35 I get 1.049999999999999
Can anyone help, or please let me know what I'm doing wrong? I am a beginner at javascript and perhaps there is also a better way to calculate fields too.
Thanks very much!
Jon
--------------------
<html>
<head>
<title>Test Form</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function calcTotal(form){
StoreOrderForm.Total1.value = (eval(StoreOrderForm.Qty1.value) * eval(StoreOrderForm.Price1.value));
StoreOrderForm.Total2.value = (eval(StoreOrderForm.Qty2.value) * eval(StoreOrderForm.Price2.value));
StoreOrderForm.Subtotal.value = (eval(StoreOrderForm.Total1.value) + eval(StoreOrderForm.Total2.value));
}
// End -->
</script>
</head>
<body>
<form method="POST" name="StoreOrderForm" action="--WEBBOT-SELF--">
<!--webbot bot="SaveResults"
U-File=" S-Format="TEXT/CSV"
S-Label-Fields="TRUE" -->
Qty: <input type="text" name="Qty1" size="20" onChange="calcTotal(this.form)" value="0.00">
Price: <input type="text" name="Price1" size="20" onChange="calcTotal(this.form)" value="0.00">
Total: <input type="text" name="Total1" size="20" value="0.00" readonly><br>
Qty: <input type="text" name="Qty2" size="20" onChange="calcTotal(this.form)" value="0.00">
Price: <input type="text" name="Price2" size="20" onChange="calcTotal(this.form)" value="0.00">
Total: <input type="text" name="Total2" size="20" value="0.00" readonly>
<p><b>Total: </b> <input type="text" name="Subtotal" size="20" value="0.00" readonly></p>
<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
</body>
</html>