Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Total Cost

Status
Not open for further replies.

PCBrandon

IS-IT--Management
Jan 6, 2007
17
Hi all,

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!
 
FYI, it should be document.frmPurReq.TotalCost.value = money(sum);

I changed that to try to troubleshoot. Without using the money function it'll just display each item's total cost as a long string in the grand total box (e.g, item 1 total cost: 5.50, item 2 total cost: 6.50, grand total would be 5.506.60). With it, I get the N.aN answer as before.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top