These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

set field property to calculate SUM of two fields

sol.manager
Registered: Oct 1 2009
Posts: 17
Answered

I have a field named "Price".
I need a javascript that will change the calculate property of this field to be "Value is the sum (+) of the following fields:"

The fields being added would be for example be "A" and "B"

The code below seems close, but sets the property to a "custom calculation script", when I just want the built in sum (+) option for the two fields being added.

this.getField("Price").setAction("Calculate","A,B");

My Product Information:
Acrobat Pro 8.1.6, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
The funciton used to perfrom the actions requested by 'Value is the ___of the following fields" is not what you think it is.

Have you tried the 'AFSimple_Calculate()' function that is used by this GUI?

this.getField("Price").setAction('Caclulate',  "AFSimple_Calculate(\"SUM\", \"A, B\");" );
Of course it is just as easy to use the custom javascript field.
this.getField("Price").setAction('Calculate', "event.value = Number(this.getField(\"A\").value) + Number(this.getField(\"B\").value);" );

George Kaiser

sol.manager
Registered: Oct 1 2009
Posts: 17
I chose your first option for setting the simple calc. At first it didn't work, but then I saw a minor typo on 'calculate' and once I changed that... it works perfectly.

Thank you for your help.