How to Create an Acrobat JavaScript If-Then Statement for PDF Forms
Question details
The user needs an Acrobat JavaScript calculation to display specific text in a PDF form field based on whether an inputted numeric amount is above or below 500,000.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Setting up conditional text outputs in a PDF form field based on specific numeric thresholds.
- Observed behavior
- The original script failed to work correctly due to the inclusion of thousands separators (commas) in the numbers and overlapping logical boundary conditions.
Ensure you are using a PDF editor that supports JavaScript form calculations, and take note of the exact field name from which you will pull the numeric amount.
Implement the corrected JavaScript conditional statement
Use pure numeric values without thousands separators and establish clear, non-overlapping boundary conditions to ensure accurate output.
JavaScript in Acrobat requires raw numbers for mathematical comparisons. Thousands separators (commas) are applied by field formatting, but the underlying value inside the code must remain pure. Additionally, ensure your if-then logic doesn't overlap on the exact boundary (e.g., using both <= and >= for 500,000) and accounts for empty fields.
Right-click the destination text field in your PDF editor's Prepare Form mode and select 'Properties'.
Go to the 'Calculate' tab in the Properties window, select 'Custom calculation script', and then click the 'Edit' button.
Start your script by retrieving the value as a number: var n = Number(this.getField("Amount").valueAsString);
Apply the if-then statement without commas: if (n == 0) event.value = ""; else if (n <= 500000) event.value = "variable rate 15 yr amortization"; else event.value = "variable rate 20 yr amortization";

Manage and Fill PDF Forms Easily with WPS Office
WPS Office provides a powerful built-in PDF editor that allows you to view, fill, and manage PDF forms seamlessly. It is a comprehensive productivity suite that meets all your document needs without the steep learning curve of advanced software.
- 1. Open WPS PDF: Launch WPS Office and open your interactive PDF document.
- 2. Access Form Tools: Navigate to the Form tab or simply click on the highlighted fillable fields to input your data.
- 3. Save your PDF: Once completed, click 'Menu' and select 'Save As' to export your filled PDF document.

Frequently Asked Questions
Why does my Acrobat JavaScript calculation fail when I use commas in numbers?
In JavaScript, commas are interpreted as operators or syntax elements, not as thousands separators. You must use raw digits (e.g., 500000 instead of 500,000) in your calculation scripts.
How do I prevent the calculation from running when the amount field is empty?
An empty field often evaluates to 0 in JavaScript. You can add a condition like 'if (n == 0) event.value = "";' at the beginning of your statement to leave the target text field blank.
What happens if my 'if-then' boundary conditions overlap?
If you use '>=' and '<=' for the exact same boundary number (like 500000), the logic creates an overlap where both conditions are technically true, leading to unpredictable results. Always use '<' for one condition and '>=' for the other.




