I am working on a simple orderform script to keep a running total,
however I am encountering some errors.
function CalculateTotal() {
var order_total = 0
// Run through all the form fields
for (var i=0; i < document.orderform.chkEvent.length - 1; ++i) {
// Is the checkbox checked?
if (document.orderform.chkEvent[i].checked) {
// If so, add value to total
order_total = (order_total + document.orderform.chkEvent.value)
//alert(order_total);
}
}
// Display the total rounded to two decimal places
//order_total = round_decimals(order_total, 2)
return order_total
}
when the alert is un-commented I always get Nan (not a number) how do
I convert the string value of my checkboxes to integers.
additionally later in my form when I try to call
document.write(order_total) I get nothing.
here is my test form below.
any help is greatly appreciated.
<form name="orderform" method="post">
<table width="71%" border="0">
<tr>
<td width="4%"><input name="chkEvent" type="checkbox"
onClick="CalculateTotal()" value="50">
<td width="20%"><p> 2:15pm </p></td>
<td width="36%"><p> Poker Run </p></td>
<td width="40%"><p> $50 </p></td>
</tr>
<tr>
<td width="4%"><input name="chkEvent" type="checkbox"
onClick="CalculateTotal()" value="10">
<td width="20%"><p> 2:15pm </p></td>
<td width="36%"><p> Poker Run </p></td>
<td width="40%"><p> $10 </p></td>
</tr>
<tr>
<td width="4%"><input name="chkEvent" type="checkbox"
onClick="CalculateTotal()" value="50">
<td width="20%"><p> 2:15pm </p></td>
<td width="36%"><p> Poker Run </p></td>
<td width="40%"><p> $50 </p></td>
</tr>
<tr>
<td width="4%"> </td>
<td width="20%"><p> </p></td>
<td width="36%"><p><strong> Total Fees </strong></p></td>
<td width="40%">
<script>
document.writeln(order_total);
</script>
</td>
</tr>
<tr>
<td width="4%"><input type="checkbox" name="chkPayment"
value="byCheck"></td>
<td width="20%"><p> </p></td>
<td width="36%"><p><strong> Pay By Check </strong></p></td>
<td width="40%"><p> </p></td>
</tr>
<tr>
<td width="4%"><input type="checkbox" name="chkPayment"
value="AtFestival"></td>
<td width="20%"><p> </p></td>
<td width="36%"><p><strong> Pay at the Festival
</strong></p></td>
<td width="40%"><p> </p></td>
</tr>
</table>
</form>