How to Fix JavaScript Syntax Errors in Acrobat Form If Statements
Question details
The user needs to resolve a JavaScript syntax error in a PDF form calculation script caused by incorrectly combined variable declarations.

- Product
- Adobe Acrobat Forms
- Device & OS
- not provided
- Scenario
- Writing a custom calculation script using JavaScript for PDF form fields.
- Observed behavior
- The script fails to execute and triggers a syntax error due to a second variable declaration placed inside the first assignment.
Open your PDF form in prepare mode, access the calculation script properties of your target field, and ensure you have the exact field names ready.
Separate Variable Declarations and Fix the Conditional Logic
Correct the syntax error by isolating variable declarations on separate lines before applying the conditional statement.
JavaScript requires strict syntax, especially when calculating values across multiple PDF form fields. A common mistake is using the var keyword inside an existing assignment, which immediately breaks the script execution.
By separating your variables and calling this.getField().value individually, the PDF viewer can correctly parse the data before evaluating your if/else logic.
Right-click the form field where the calculation happens, select Properties, and navigate to the Calculate tab.
Click 'Edit' to open the JavaScript editor. Locate the incorrect line, such as var A = this.getField("<Actual>").value + var B = ...
Change the code to declare each variable on a new line: var A = this.getField("<Actual>").value; var B = this.getField("<Google Maps>").value / 2;
Add your condition below the variables: if (B > A) { event.value = B; } else { event.value = this.getField("<Value>").value; }
Click OK to close the editor and properties window. Enter test data into your form fields to verify the calculation runs without errors.

Simplify Document Processing with WPS Office
If you are dealing with complex Adobe Acrobat scripts and need an easier way to manage documents, consider WPS Office. It offers a lightweight, highly compatible alternative for PDFs, Word documents, Excel spreadsheets, and PowerPoint presentations.
- 1. Download the installer: Visit the official WPS Office website and download the free installation package.
- 2. Install the software: Run the installer and follow the on-screen prompts to set up WPS Office on your device.
- 3. Open your PDF: Launch WPS Office and open your PDF document to access intuitive editing and viewing tools without complex scripting.

Frequently Asked Questions
Why does combining variables with var cause a syntax error in JavaScript?
In JavaScript, the var keyword is exclusively used to declare a variable. You cannot place a declaration keyword inside an arithmetic operation or another assignment. They must be declared sequentially.
How do I access a specific field's value in a PDF form script?
You use the this.getField("FieldName").value method. Ensure the field name string exactly matches the name defined in the PDF form, including capitalization and special characters.
Where does the calculated result go in a PDF form script?
The final result of your calculation is assigned to event.value. This command tells the PDF software to display that specific value in the form field where the calculation script is running.




