PCBrandon
IS-IT--Management
- Jan 6, 2007
- 17
Hi all,
I have the following code:
rowTotal() computes an item's total cost by multiplying its quantity by its cost. It also makes a grand total of all the item's total costs of each row. This part doesn't work. It'll work if there's only one item, but when I add an item the grand total becomes "N.aN".
Any thoughts as to why this isn't working? Thanks!
I have the following code:
Code:
<script language="JavaScript">
<!--
function rowTotal(index){
quant = document.frmPurReq.ItemQuan[--index].value;
cost = document.frmPurReq.ItemCost[index].value;
document.frmPurReq.ItemTotal[index].value = money(quant * cost);
sum = 0.00;
for(i=0; i<document.frmPurReq.ItemTotal.length; i++)
sum += parseFloat(document.frmPurReq.ItemTotal[i].value);
document.frmPurReq.TotalCost.value = sum;
}
function money(amt){
old = amt
bignum = Math.round(amt*100).toString();
if (bignum == "0") bignum = "000";
theend = bignum.substring(bignum.length-2, bignum.length);
thebeginning = bignum.substring(0, bignum.length-2);
return thebeginning + "." + theend;
}
//-->
</script>
rowTotal() computes an item's total cost by multiplying its quantity by its cost. It also makes a grand total of all the item's total costs of each row. This part doesn't work. It'll work if there's only one item, but when I add an item the grand total becomes "N.aN".
Any thoughts as to why this isn't working? Thanks!