Hi,
Can someone help with my code. I want to calculate the total sum of document.form1.Total[i].value to put in the Grand Total box and i dont know how to do it without explicitly entering [0],[1] etc as Ive done here (Ill be adding more items). My code is below. Ive pasted in the lot so you can see what Im trying to acheive.
Thanks!
<script language=”JavaScript” type=”text/javascript”>
function calcTotal(){
var i;
for (i=0; i<document.form1.Total.length; i++)
{
var LP = parseFloat(document.form1.ListPrice[i].value);
var Q = parseInt(document.form1.Qty[i].value);
document.form1.Total[i].value = (LP * Q);
Tot = parseFloat(document.form1.Total[0].value) + parseFloat(document.form1.Total[1].value);
document.form1.GrandTotal.value = Tot;
}
}
</script>
<form action=”#” name=”form1″>
<table border=”1″>
<tr>
<td>Printer
</td>
<td>List Price
</td>
<td>Qty
</td>
<td>Total
</td>
</tr>
<tr>
<td>Printer A
</td>
<td><input type=”text” name=”ListPrice” value=”123.04″ readonly=””>
</td>
<td><input type=”text” name=”Qty” value=”0″ onkeyup=”calcTotal();”>
</td>
<td><input type=”text” name=”Total” value=”0″>
</td>
</tr>
<tr>
<td>Printer B
</td>
<td><input type=”text” name=”ListPrice” value=”543″ readonly=””>
</td>
<td><input type=”text” name=”Qty” value=”0″ onkeyup=”calcTotal();”>
</td>
<td><input type=”text” name=”Total” value=”0″>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td align=”right”>Grand Total =
</td>
<td><input type=”text” name=”GrandTotal”>
</td>
</tr>
</table>
</form>