Thane,

I can get the fields to sum correctly by ensuring that the initial value of:

window.document.ExpenseForm.GrandTotalAmount.value = 0;

outside the while loop;


<SCRIPT language="Javascript">
        function addTotals()
                {
                i = 0
                window.document.ExpenseForm.GrandTotalAmount.value = i;
                while (i <= #GetFormInfo.RecordCount#)
                        {
                        
window.document.ExpenseForm.GrandTotalAmount.value=parseFloat(window.document.ExpenseForm.GrandTotalAmount.value)+parseFloat(eval("window.document.ExpenseForm.TotalAmount"+i+".value"));
                        i++
                        }
                }
</SCRIPT>

- mike

-----Original Message-----
From: Thane Sherrington [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, October 01, 2002 11:29 AM
To: CF-Talk
Subject: -OT- Another Javascript problem with forms


Ok, I got my two fields to add up and display in another field with this:

onchange="window.document.ExpenseForm.TotalAmount#Line#.value=parseFloat(window.document.ExpenseForm.Mileage#Line#.value)+parseFloat(window.document.ExpenseForm.CostOfMeals#Line#.value);addTotals();"

Now I'm trying to add up all the TotalAmounts and put it at the bottom of 
the form.  I need to loop through the entire list from 1 to #list# on each 
onChange and update the GrandTotal.  I can't figure out how to loop in 
Javascript and hand it a dynamic variable name.  I tried this:

<SCRIPT language="Javascript">
        function addTotals()
                {
                i = 0
                while (i <= #GetFormInfo.RecordCount#)
                        {
                        
window.document.ExpenseForm.GrandTotalAmount.value=parseFloat(window.document.ExpenseForm.GrandTotalAmount.value)+parseFloat(eval("window.document.ExpenseForm.TotalAmount"+i+".value"));
                        i++
                        }
                }
</SCRIPT>

But it doesn't work doesn't appear to go through each variable name.  How 
would I do this?

T


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Your ad could be here. Monies from ads go to support these lists and provide more 
resources for the community. http://www.fusionauthority.com/ads.cfm

Reply via email to