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

Calculation Script Help!

TrishM
Registered: Oct 5 2010
Posts: 6
Answered

I am trying to calculate a final figure from 3 sources and keep getting syntax errors. Text field 1 (TF1) is a dollar amount, Text field 2 (TF2) is a % and Text field 3 (TF3)is $ amount as well. My final calculation should represent (TF1 * (TF2/2)) + TF3 = result. I have used the custom code in the format tabs to have the numbers shown as $ or %, but can't get the calculation script to work. I have
 
var a = get.thisField(TF1).value;
var b = get.thisField(TF2).value;
var c = get.thisField(TF3).value;
 
event.value = (a * (b/2) + c;
 
How would I get this to calculate correctly? The final result should look something like this:
 
TF1 = $100,000
TF2 = 10%
TF3 = $500
Result should be (100,000*(.10/2))+500 = $5,500
 
Any help would be greatly appreciated.

My Product Information:
Acrobat Pro 9.3.1, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Try: event.value = (a * b/2) + c;
TrishM
Registered: Oct 5 2010
Posts: 6
Okay I tried that and it gives me a Syntax Error stating:

SyntaxError: missing ) after argument list 1: at line 2.

It works fine if I take out one of the variables, but i get this syntax error at the same spot everytime I add the 3rd variable.
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
On a closer second look, there's more wrong with you script. Copy what I've shown below and paste it, replacing everything else you may already have:



var a = getField("TF1").value;
var b = getField("TF2").value;
var c = getField("TF3").value;

event.value = (a * b/2) + c;

Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
Hi TrishM,

There are more problems with your script than a missing ). There is no such object as "get" and there is no function "this.field" and you left out quotes around the field names. This script should not work at all- too many problems with it. You should read these aritcles for some basic scripting help-

http://acrobatusers.com/tutorials/why-doesnt-my-script-work

http://acrobatusers.com/tutorials/how-debug-your-script

Hope this helps,

Dimitri

TrishM
Registered: Oct 5 2010
Posts: 6
Thank you for your help... it worked beautifully! And thanks for the links, I will definately do some refreshing! Thanks again!