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.orderf orm.chkEvent.le ngth - 1; ++i) {
// Is the checkbox checked?
if (document.order form.chkEvent[i].checked) {
// If so, add value to total
order_total = (order_total + document.orderf orm.chkEvent.va lue)
//alert(order_tot al);
}
}
// 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%"><inp ut name="chkEvent" type="checkbox"
onClick="Calcul ateTotal()" 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%"><inp ut name="chkEvent" type="checkbox"
onClick="Calcul ateTotal()" 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%"><inp ut name="chkEvent" type="checkbox"
onClick="Calcul ateTotal()" 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%">&nbs p;</td>
<td width="20%"><p> </p></td>
<td width="36%"><p> <strong> Total Fees </strong></p></td>
<td width="40%">
<script>
document.writel n(order_total);
</script>
</td>
</tr>
<tr>
<td width="4%"><inp ut type="checkbox" name="chkPaymen t"
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%"><inp ut type="checkbox" name="chkPaymen t"
value="AtFestiv al"></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>