Fix Acrobat JavaScript If-Else Syntax and Form Calculation Errors
Question details
The user needs to correct a custom calculation script in a PDF form to accurately return conditional values, set minimum and maximum limits, and handle zero inputs by returning a blank value.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Setting up a custom calculation script in a PDF form to dynamically adjust field values based on specific conditions.
- Observed behavior
- The target calculation field currently produces no output despite having conditions set for minimum, maximum, and intermediate calculations.
Ensure that JavaScript is enabled in your PDF viewer preferences and verify that the field names referenced in your script (e.g., 'Text9') exactly match the names in your form.
Use validated JavaScript syntax with event.value
Update your custom calculation script to properly validate input numbers and assign the output directly to the event.value property.
Acrobat form calculations require rigorous handling of empty or non-numeric fields. By converting the field value to a number and checking for NaN (Not a Number), you can prevent silent script failures.
Open Adobe Acrobat, navigate to the 'Tools' menu, and select 'Prepare Form' to enable form editing.
Right-click the calculation field that is failing to produce output and select 'Properties' from the context menu.
Go to the 'Calculate' tab, select 'Custom calculation script', and click the 'Edit' button.
Enter the following code: var v1 = Number(this.getField("Text9").valueAsString); if (isNaN(v1) || v1 === 0) event.value = ""; else if (v1 < 100) event.value = 200; else if (v1 <= 150) event.value = v1 + 100; else event.value = 250;
Click 'OK', close the properties window, and test the form by entering a numeric value into the source field (Text9).

Use an alternative conditional logic structure
Implement an alternative script utilizing event.target.value and explicit number conversion to handle the form calculation.
View and Manage Interactive PDF Forms with WPS Office
While creating complex JavaScript calculation forms often requires advanced authoring tools, WPS Office provides a lightweight, seamless experience for viewing, filling, and managing interactive PDF forms.
- 1. Download and Install: Download and install WPS Office from the official website onto your computer.
- 2. Open PDF Form: Launch WPS PDF and open your interactive PDF document containing the form fields.
- 3. Fill the Fields: Click on the form fields to input your data. Calculation fields will automatically update based on the document's built-in rules.
- 4. Save and Export: Once completed, click 'Save' to securely store your filled-out PDF form or share it directly.

Frequently Asked Questions
Why is my PDF form calculation script producing no output?
This usually happens if JavaScript is disabled in your PDF viewer, the script contains syntax errors (like missing braces), or the field names referenced in the code do not perfectly match the actual form field names.
How do I leave a PDF calculation field blank if the value is zero?
You can achieve this by adding a conditional check in your JavaScript code, such as 'if (v1 === 0) { event.value = ""; }', which explicitly sets the calculation field's value to an empty string.
Should I use event.value or event.target.value in Acrobat?
In Acrobat custom calculation scripts, it is standard practice to assign the result directly to 'event.value'. Using 'event.target.value' can also work in some contexts, but 'event.value' is generally preferred for calculating the active field.




