RE: Adding two fields and displaying in a third
At 12:48 PM 9/30/02 -0400, S. Isaac Dealey wrote: you could also use parseInt(string) or parseFloat(string) although if it doesn't find an integer or a string at the beginning of the string it will return NaN rather than . Also if there are non-numeric values on the end of the string it will remove them. 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 __ This list and all House of Fusion resources hosted by CFHosting.com. The place for dependable ColdFusion Hosting. FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
RE: Adding two fields and displaying in a third
thane, it's trying to concatenate them instead of adding, try something like this(forcing the values into numbers then adding them): input type=Text name=CostOfMeals#Line# value=0 validate=float required=Yes size=5 maxlength=5 onchange= var num1=new Number(eval(window.document.ExpenseForm.Mileage#Line#)); var num2=new Number(eval(window.document.ExpenseForm.CostOfMeals#Line#)); window.document.ExpenseForm.TotalAmount#Line#.value = num1 + num2; hth -seth -Original Message- From: Thane Sherrington [mailto:[EMAIL PROTECTED]] Sent: Monday, September 30, 2002 11:04 AM To: CF-Talk Subject: Adding two fields and displaying in a third I'm writing a form that allows a person to fill in the mileage and meal expense, and then displays the total in a third field. I'm using this in the meals expense field: input type=Text name=CostOfMeals#Line# value=0 validate=float required=Yes size=5 maxlength=5 onchange=window.document.ExpenseForm.TotalAmount#Line#.value=eval(window.document.ExpenseForm.Mileage#Line#)+eval(window.document.ExpenseForm.CostOfMeals#Line#); But the third field evaluates to [object][object]. How do I get this to add up? T __ Signup for the Fusion Authority news alert and keep up with the latest news in ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
RE: Adding two fields and displaying in a third
onchange=window.document.ExpenseForm.TotalAmount#Line#.value=eval (window.document.ExpenseForm.Mileage#Line#)+eval(window.document. ExpenseForm.CostOfMeals#Line#); Add .value to the end of the 2 fields you're trying to add, as in: ...=eval(window.document.ExpenseForm.Mileage#Line#.value)+... ^^ BTW, why are you using eval()? -- Mosh Teitelbaum evoch, LLC Tel: (301) 625-9191 Fax: (301) 933-3651 Email: [EMAIL PROTECTED] WWW: http://www.evoch.com/ -Original Message- From: Thane Sherrington [mailto:[EMAIL PROTECTED]] Sent: Monday, September 30, 2002 11:04 AM To: CF-Talk Subject: Adding two fields and displaying in a third I'm writing a form that allows a person to fill in the mileage and meal expense, and then displays the total in a third field. I'm using this in the meals expense field: input type=Text name=CostOfMeals#Line# value=0 validate=float required=Yes size=5 maxlength=5 onchange=window.document.ExpenseForm.TotalAmount#Line#.value=eval (window.document.ExpenseForm.Mileage#Line#)+eval(window.document.E xpenseForm.CostOfMeals#Line#); But the third field evaluates to [object][object]. How do I get this to add up? T __ 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 FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
RE: Adding two fields and displaying in a third
forgot the .values on the end of each var, that's why it was putting in [object], should work now. -Original Message- From: Turetsky, Seth Sent: Monday, September 30, 2002 11:19 AM To: '[EMAIL PROTECTED]' Subject: RE: Adding two fields and displaying in a third thane, it's trying to concatenate them instead of adding, try something like this(forcing the values into numbers then adding them): input type=Text name=CostOfMeals#Line# value=0 validate=float required=Yes size=5 maxlength=5 onchange= var num1=new Number(eval(window.document.ExpenseForm.Mileage#Line#.value); var num2=new Number(eval(window.document.ExpenseForm.CostOfMeals#Line#.value); window.document.ExpenseForm.TotalAmount#Line#.value = num1 + num2; hth -seth -Original Message- From: Thane Sherrington [mailto:[EMAIL PROTECTED]] Sent: Monday, September 30, 2002 11:04 AM To: CF-Talk Subject: Adding two fields and displaying in a third I'm writing a form that allows a person to fill in the mileage and meal expense, and then displays the total in a third field. I'm using this in the meals expense field: input type=Text name=CostOfMeals#Line# value=0 validate=float required=Yes size=5 maxlength=5 onchange=window.document.ExpenseForm.TotalAmount#Line#.value=eval(window.document.ExpenseForm.Mileage#Line#)+eval(window.document.ExpenseForm.CostOfMeals#Line#); But the third field evaluates to [object][object]. How do I get this to add up? T __ Structure your ColdFusion code with Fusebox. Get the official book at http://www.fusionauthority.com/bkinfo.cfm FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
RE: Adding two fields and displaying in a third
You didn't get the value, but the object: input type=Text name=CostOfMeals#Line# value=0 validate=float required=Yes size=5 maxlength=5 onchange=window.document.ExpenseForm.TotalAmount#Line#.value=eval(windo w.document.ExpenseForm.Mileage#Line#.value)+eval(window.document.Expense Form.CostOfMeals#Line#.value); -Original Message- From: Thane Sherrington [mailto:[EMAIL PROTECTED]] Sent: maandag 30 september 2002 17:04 To: CF-Talk Subject: Adding two fields and displaying in a third I'm writing a form that allows a person to fill in the mileage and meal expense, and then displays the total in a third field. I'm using this in the meals expense field: input type=Text name=CostOfMeals#Line# value=0 validate=float required=Yes size=5 maxlength=5 onchange=window.document.ExpenseForm.TotalAmount#Line#.value=eval(windo w.document.ExpenseForm.Mileage#Line#)+eval(window.document.ExpenseForm.C ostOfMeals#Line#); But the third field evaluates to [object][object]. How do I get this to add up? T __ Structure your ColdFusion code with Fusebox. Get the official book at http://www.fusionauthority.com/bkinfo.cfm FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
RE: Adding two fields and displaying in a third
At 11:22 AM 9/30/02 -0400, Mosh Teitelbaum wrote: onchange=window.document.ExpenseForm.TotalAmount#Line#.value=eval (window.document.ExpenseForm.Mileage#Line#)+eval(window.document. ExpenseForm.CostOfMeals#Line#); Add .value to the end of the 2 fields you're trying to add, as in: ...=eval(window.document.ExpenseForm.Mileage#Line#.value)+... ^^ Shoot. Thanks. :) BTW, why are you using eval()? I thought I had to in order to get Javascript to treat as numbers instead of text. T __ This list and all House of Fusion resources hosted by CFHosting.com. The place for dependable ColdFusion Hosting. FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
RE: Adding two fields and displaying in a third
At 11:22 AM 9/30/02 -0400, Mosh Teitelbaum wrote: onchange=window.document.ExpenseForm.TotalAmount#Line#.value=eval (window.document.ExpenseForm.Mileage#Line#)+eval(window.document. ExpenseForm.CostOfMeals#Line#); Add .value to the end of the 2 fields you're trying to add, as in: ...=eval(window.document.ExpenseForm.Mileage#Line#.value)+... ^^ Shoot. Thanks. :) BTW, why are you using eval()? I thought I had to in order to get Javascript to treat as numbers instead of text. you could also use parseInt(string) or parseFloat(string) although if it doesn't find an integer or a string at the beginning of the string it will return NaN rather than . Also if there are non-numeric values on the end of the string it will remove them. S. Isaac Dealey Certified Advanced ColdFusion 5 Developer www.turnkey.to 954-776-0046 __ This list and all House of Fusion resources hosted by CFHosting.com. The place for dependable ColdFusion Hosting. FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
RE: Adding two fields and displaying in a third
At 11:22 AM 9/30/02 -0400, Mosh Teitelbaum wrote: onchange=window.document.ExpenseForm.TotalAmount#Line#.value=eval (window.document.ExpenseForm.Mileage#Line#)+eval(window.document. ExpenseForm.CostOfMeals#Line#); Add .value to the end of the 2 fields you're trying to add, as in: ...=eval(window.document.ExpenseForm.Mileage#Line#.value)+... ^^ Shoot. Thanks. :) Yah, no prob 8^) BTW, why are you using eval()? I thought I had to in order to get Javascript to treat as numbers instead of text. Nope, you shouldn't have to. JavaScript is supposed to add 2 values together (via the + operator) if the values can both be resolved to numerics. Otherwise, it appends the values. So long as both of your values are numeric then, it should resolve just fine. -- Mosh Teitelbaum evoch, LLC Tel: (301) 625-9191 Fax: (301) 933-3651 Email: [EMAIL PROTECTED] WWW: http://www.evoch.com/ __ Signup for the Fusion Authority news alert and keep up with the latest news in ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
RE: Adding two fields and displaying in a third
At 02:49 PM 9/30/02 -0400, Mosh Teitelbaum wrote: Nope, you shouldn't have to. JavaScript is supposed to add 2 values together (via the + operator) if the values can both be resolved to numerics. Otherwise, it appends the values. So long as both of your values are numeric then, it should resolve just fine. Ok, great. I'll drop the eval. Thanks again. T __ Get the mailserver that powers this list at http://www.coolfusion.com FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists