7 Replies Latest reply on Oct 4, 2011 11:31 AM by Starbuck68

# Can someone help me how to figure out the syntax for a calculation in an Acrobat fillable form?

For the first time I'm creating a fillable PDF form for a kid's summer camp brochure. After countless hours I've been able to figure out how to do simple calculations (number of camp sessions x price = Subtotal). But I can't figure out how to create a script that will take the Subtotal figure and generate a number that is 10% of the Subtotal. All I want to do is to have a separate field (the Discount) that can reference the Subtotal amount, and if it is more than \$170.00, calculates and displays a figure that equals 10% of that amount. From there I can figure out how to subtract the 10% from the Subtotal, but I can't figure out the syntax for calculating that 10%. Also I don't know if that should be entered in the Simple Field Notation box or Custom Calculation Script box of the Calculate area in the Text Field Properties Box. Any help would be sorely appreciated!!!

• ###### 1. Re: Can someone help me how to figure out the syntax for a calculation in an Acrobat fillable form?

You need to use JavaScript. It would be something like:

// Custom calculation script for Discount field

(function () {

// Get the subtotal value, as a number

var subtotal = +getField("Subtotal").value;

// Set this field's value

// If it's greater than 170, calculate 10%, otherwise it's zero

event.value = subtotal > 170 ? .1 * subtotal : 0;

})();

That last line is equivalent to:

if (subtotal > 170) {

event.value = .1 * subtotal;

} else {

event.value = 0;

}

It's just more compact.

Replace "Subtotal" in the getField line above with the actual name of the subtotal field. Also, set all calculated fields to readonly. And check to make sure the field calculation order is correct.

• ###### 2. Re: Can someone help me how to figure out the syntax for a calculation in an Acrobat fillable form?

George, thank you for responding. I pasted in your code and made sure the naming formats were correct. What resulted was the figure "10%" appeared on the line that I reserved for the Discount (what I would like to appear is the actual monetary value of the discount -- Subtotal X 10%) Also, the 10% of the Subtotal figure (in this case was \$222.00)  came out to \$22.22, which should have given me a total of \$199.80, but instead came back with a total of \$212.00. I know I'm doing something wrong but don't know what!

• ###### 3. Re: Can someone help me how to figure out the syntax for a calculation in an Acrobat fillable form?

You probably have the discount field set up to use a percentage format. Instead, it should be set to a number format.

The incorrect calculation could be due to the field calculation order being incorrect. To check it, go into forms editing mode (Form > Add or Edit fields) and select "Forms > Edit Fields > Set Field Calculation Order".

• ###### 4. Re: Can someone help me how to figure out the syntax for a calculation in an Acrobat fillable form?

Of course you were absolutely correct on all accounts. Thank you so much for your help -- it saved me hours of frustration!!

• ###### 5. Re: Can someone help me how to figure out the syntax for a calculation in an Acrobat fillable form?

Hi George. I just noticed that the discount box is just giving a straight \$10 discount, not a 10% discount based on what the Subtotal number is i.e. \$10 discount whether the subtotal is \$230 or \$780. Any thoughts offhand what I'm doing wrong?

Mary Anne

• ###### 6. Re: Can someone help me how to figure out the syntax for a calculation in an Acrobat fillable form?

The code I posted works for me. Are you using the exact same code? If so, it's hard to tell without seeing the file. I'd be happy to take a look if you are free to  post it somewhere or or can email it to me. My addess is in my profile.

• ###### 7. Re: Can someone help me how to figure out the syntax for a calculation in an Acrobat fillable form?

I sent you a PM with a similar question. I have no idea how to right the code.