3 Replies Latest reply on Sep 30, 2013 11:43 PM by George_Johnson

# Need Help With Custom Calculation Script

Hey everyone.  I'm using Acrobat Pro X and stumbling a bit on the syntax for the following equation.  I need to add the value of "Cell1" & "Cell2" then add the value of "Cell3".  However,the value of "Cell3" is entered by the user and specifies a percentage of the sum of "Cell1 & "Cell2".  For example: If the user enters "3" into "Cell3" I need the returned value to be 3% of the sum of "Cell1" + "Cell2".  If the user enters "9" into "Cell3" I need the returned value for "Cell3" to be 9% of the sum of "Cell1 & Cell2" and the end result needs to be the sum of "Cell1+Cell2+Cell3".  In greater detail:

If "Cell1" = \$500, "Cell2" = \$500 and "Cell3" = "3" then I need the returned value to be \$1030.00.

I hope this makes sense. Here's what I have so far but alas, it's not working.  Any help would be GREATLY appreciated.

// Get first field value, as a number

var v1 = +getField("Cell1").value;

// Get second field value, as a number

var v2 = +getField("Cell2").value;

// Get processing field value, as a number

//var v3 = +getField("Cell3"/100).value;

// Calculate and set this field's value to the result

event.value = v3+(v1+v2);

Thanks,

Solan

• ###### 1. Re: Need Help With Custom Calculation Script

I posted an answer but realized it wasn't what you wanted. There is some confusion about what you want for Cell3. On the one hand, you say you want the user to enter a vaule in the field, but them you say you want its value to be calculated based on what the user enters and two other field values. It seems to me Cell3 should be the field that the user enters the percentage and the calculated field's (Cell4) script could then be:

// Get first field value, as a number

var v1 = +getField("Cell1").value;

// Get second field value, as a number

var v2 = +getField("Cell2").value;// Get processing field value, as a number

// Get the percentage

var v3 = +getField("Cell3").value;

// Calculate and set this field's value to the result

event.value = (1 + v3 / 100) * (v1 + v2);

• ###### 2. Re: Need Help With Custom Calculation Script

George,

You're the man!  One logic question: why add the "1" to v3 in the last statement?

---- "event.value = (1 + v3 / 100) * (v1 + v2);" ---

I never would have considered that.  Wouldn't v3/100*(v1+v2); work as well?

Thanks again.

Solan

• ###### 3. Re: Need Help With Custom Calculation Script

The latter gives you the percentage of v1 + v2 that you want to then add to v1 + v2. So the former is the same as:

(v1 + v2)   +   v3/100 * (v1 + v2)