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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

summing values in the same form page.

Status
Not open for further replies.

omerdurdu

Programmer
Jul 21, 2001
72
TR
Hello,
I have a form page with input boxes. What I would like to do
sum the values in the input boxes in the same page. here is the a sample code.
<cfform name=&quot;aa&quot; action=&quot;update.cfm&quot;>
<input type=&quot;text&quot; name=&quot;cc&quot; value=&quot;0&quot;>
<input type=&quot;text&quot; name=&quot;bb&quot; value=&quot;0&quot;>
<input type=&quot;text&quot; name=&quot;dd&quot; value=&quot;0&quot;>
<input type=&quot;text&quot; name=&quot;ee&quot; value=&quot;0&quot;>

<cfset total=#cc#+#bb#+#dd#+#ee#>

</cfform


Can I do something like this.
cfset can be out of form.
Thanks for help
 
sure, you can do that, but only on the action page, in your case update.cfm, because the values that the user enters will not be availabe to coldfusion until the form is submitted

you could sum them up with javascript using a hidden form field and an onsubmit event, but i don't see what the advantage would be...

rudy
 
Thanks for your replay.
Can you show me the javascript code.
Thanks
 
var result
function addemup() {
var r = 0
r += document.aa.cc.value - 0
r += document.aa.bb.value - 0
r += document.aa.dd.value - 0
r += document.aa.ee.value - 0
result = r
}

caution: the above is untested

you have to define another hidden field and then assign it the value of result in an onsubmit event

since you're using CFFORM instead of FORM, i don't know how to do that

like i said, i don't see the advantage of doing this with javascript when you can do it just as easily in the action page with coldfusion

besides, it's not going to get executed for users who have javascript turned off

rudy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top