Fix If/Else JavaScript in Acrobat Custom PDF Calculations
Question details
The user needs to troubleshoot an if/else JavaScript calculation in a PDF form that should leave a specific field blank when an offer price is below or equal to a specified amount.

- Product
- Adobe Acrobat / PDF
- Device & OS
- not provided
- Scenario
- Creating custom calculation scripts for interactive PDF forms to automate value outputs based on numerical conditions.
- Observed behavior
- The calculation script fails to execute or update the target fields properly, typically due to syntax errors such as incorrect capitalization or improper field value assignments.
Ensure you have the exact, case-sensitive names of the form fields you want to reference in your JavaScript, as mismatched names are the most common cause of calculation failures.
Use the Correct getField Method and Value Property
Fix common JavaScript syntax errors by using the case-sensitive getField method and correctly assigning outcomes to the target field's value property.
Acrobat relies on a specific Document Object Model (DOM) where variables must be explicitly defined, and fields must be referenced using `this.getField("FieldName")`. A frequent mistake is typing a lowercase `getfield` or attempting to assign a value directly to a field name string instead of its `.value` property.
Open your PDF form in Adobe Acrobat and enter Form Editing mode. Right-click the field where the calculation should occur and select 'Properties'.
Navigate to the 'Calculate' tab, select 'Custom calculation script' from the options, and click the 'Edit' button.
Ensure your script uses `this.getField("field_name")` with exact spelling and capitalization. To compare numerical values, use `.valueAsNumber` (e.g., `this.getField("offer_price").valueAsNumber`).
Correct the assignment logic by accessing the `.value` property. For example: `if (this.getField("offer_price").valueAsNumber <= 100000) { this.getField("payment_amount").value = ""; } else { this.getField("payment_amount_3").value = 0; }`.
Click 'OK' to save the script, close the properties dialog, and preview the form to test if the calculation works as intended.

Edit and Manage PDF Forms Easily with WPS Office
WPS Office provides a comprehensive, lightweight PDF editor that allows you to seamlessly view, fill, and manage interactive PDF forms without the complexity of heavy scripting.
- 1. Launch WPS Office: Open WPS Office and click on the 'PDF' tab on the home screen to launch the built-in PDF editor.
- 2. Open your PDF form: Browse and open your interactive PDF form document within the application.
- 3. Fill the form fields: Use the 'Form' or 'Fill & Sign' tools to input your data directly into the calculated fields.
- 4. Save your document: Click 'Save' or export the filled PDF document securely to your local drive or cloud storage.

Frequently Asked Questions
Why does my Acrobat JavaScript return a syntax error on getField?
JavaScript is case-sensitive. Using 'getfield' with a lowercase 'f' instead of 'getField' will result in a syntax error and prevent the calculation script from running.
How do I leave a PDF form field blank using JavaScript?
To leave a form field blank, you must assign an empty string to its value property. For example: `this.getField("YourFieldName").value = "";`
Why is my if/else condition not triggering correctly based on a numeric value?
When comparing numbers, ensure you are retrieving the field's value as a number rather than a text string. Use `this.getField("FieldName").valueAsNumber` in your if condition for accurate numerical comparisons.
Do I need to define variables in Adobe Acrobat calculations?
Yes, if you use a variable name like 'payment_amount' without defining it using 'var' or linking it to an actual field via 'getField()', the script will fail. Always explicitly define variables or reference the exact field objects.




