How to Fix Acrobat JavaScript Syntax Error in a Form Calculation
Question details
The user is encountering a syntax error and incorrect addition results when running a custom JavaScript form calculation in a PDF document.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Writing and executing a custom JavaScript calculation script for PDF form fields.
- Observed behavior
- The calculation script throws a syntax error due to unmatched closing patterns, and it concatenates values instead of adding them because the fields are read as blank or unformatted strings.
Before making changes to your script, verify the exact spelling and capitalization of all your form fields, as JavaScript is case-sensitive and mismatched names will immediately cause errors.
Correct Syntax Structure and Apply Numeric Conversion
Fix the script by removing unnecessary function declarations to resolve syntax errors, and explicitly convert form field values to numbers so they calculate correctly.
When pulling values directly from PDF form fields, Adobe Acrobat initially treats them as text strings. If you try to add them without explicit conversion, the system will concatenate the text instead of doing mathematical addition (e.g., '1' + '2' becomes '12'). Additionally, copying script templates with unbalanced parentheses or stray function declarations will break the script entirely.
Right-click the target calculation field in your PDF form and select 'Properties' from the context menu.
Click on the 'Calculate' tab, select the 'Custom calculation script' radio button, and click the 'Edit' button to open the JavaScript editor.
Review your code and remove any unnecessary first and last lines, ensuring there is a left parenthesis at the very beginning if required, and delete any unmatched closing brackets.
Modify your variable assignments to explicitly convert the field value to a number. Place a unary plus sign (+) before the field retrieval. For example: var v1 = +this.getField("Accountability1").value;
Add your converted numeric variables together and assign the final mathematical result to event.value.

Edit and Process PDF Forms with WPS Office
If you frequently work with PDF documents and fillable forms, WPS Office provides a lightweight, comprehensive PDF editor. View, fill, and manage PDF forms efficiently without overwhelming complexity.
- 1. Download and Install: Download WPS Office from the official website and run the installer on your device.
- 2. Open Your PDF: Launch WPS Office, click 'Open' on the home screen, and select your PDF form file.
- 3. Edit and Fill: Navigate to the 'Edit' or 'Form' tab to interact with form fields, highlight text, or make structural changes to your document layout seamlessly.

Frequently Asked Questions
Why is my PDF form calculation concatenating numbers instead of adding them?
Form field values are extracted as strings by default. If you use the '+' operator without converting the strings to numbers first, JavaScript will link the text together. Using a unary plus (like +this.getField) forces numeric addition.
What causes an 'unmatched closing pattern' error in Acrobat?
This syntax error occurs when your script contains an extra closing brace '}', bracket ']', or parenthesis ')' without a corresponding opening character. Removing unnecessary function wrapping or checking your brackets often resolves this.
How do I deal with blank form fields in a calculation script?
Blank fields return empty strings, which can break equations. Converting the field value to a number using the unary '+' operator automatically turns an empty string into a 0, allowing the mathematical calculation to continue accurately.




