Expand my Community achievements bar.

Calculation with JavaScript

Avatar

Former Community Member
Hello,

i have two numeric fields on my form and I just want to calculate the sum

of these two fields and display it in another field. The calucuation should

happen whenever someone changes one of the two fields and not by pressing a button or something like that.



Thanks for your support!

Alex
3 Replies

Avatar

Former Community Member
This is quite simple using FormCalc as your scripting language. Suppose I have three fields on my form called "NumericField1", "NumericField2" and "Total". In the "Calculate" event of my Total field I add the following script:



Sum (NumericField1, NumericField2)



Any time a user changes the value of either NumericField1 or NumericField2, the value in the Total field will automatically calculate.

Avatar

Former Community Member
The same applies if you want to use JavaScript.



Total.rawValue = NUmerField1.rawValue + NumerField2.rawValue;

Avatar

Level 1

I am trying to perform a simple calculation and put the results into each field of an array of numeric fields.  I am using Javascript in LifeCycle 8.  I am a total newbie to Adobe programming, but I have extensive programming experience in other environments.  All I really need to know is the correct syntax to add values to each item in a numeric field array.

e.g. #1

var Total;

Total = 23;

nf[0].rawValue = Total;

nf[1].rawValue = Total + 1;

nf[2].rawValue = Total + 2;

THIS DOESN'T WORK ????  I also tried the following

e.g.

var Total;

Total = 23;

nf.rawValue = Total;

nf.index = 1;

nf.rawValue = Total + 1;

nf.index = 2;

nf.rawValue = Total + 2;

This also doesn't work. please help me add values to specific items within the numeric field array, this is driving me nuts.....