Link to home
Start Free TrialLog in
Avatar of Rush_2112
Rush_2112

asked on

How to add values of input fields?

Hi,

I have a flashform with several input fields that I need to do math on.

I have an onChange event that's called whenever the values of the 2 fields change.

--------
<cfsavecontent variable="codepacket">
three.value = one.value + two.value;
</cfsavecontent>
---------

onChange="#codepacket#"
----------

<cfsavecontent variable="codepacket">
three.value = one.value + two.value;
</cfsavecontent>

------------

The problem here is that it adds the text together, not the values.  So if someone enters 1 in the first box and 2 in the second, I get '12' in the third box, not 3.

Thanks for the help!

Avatar of ugeb
ugeb
Flag of United States of America image

Hi,

Try changing
three.value = one.value + two.value;

to

three.value = (one.value +0) +( two.value+0)

this should force the conversion from string to number.

HTH
Gene
;


Avatar of Rush_2112
Rush_2112

ASKER

Now the form doesn't load at all :(
Do you get compile errors? I didn't put a semicolon at the end of the statement above, did you add it?  what errors are you getting?

What version of actionscript are you using?
This is inside a coldfusion flashform, so I don't know what version it's using.  There's no specific errors, the form just doen't load and I'm left with a blank page.

Thanks
Well, I've never used cold fusion, so I can't address that specifically, but if that doesn't work, try:

three.value = String((Number(one.value) + Number( two.value));

three is another textfield, correct?


Hi, I just realized your syntax doesn't look like actionscript, just that one line. With all the angle brackets and such, what language is this?  I've given you actionscript, which probably won't work in some other language.
ASKER CERTIFIED SOLUTION
Avatar of kishoregp
kishoregp
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That was what I was looking for!  Good show!