PDF Editing Issues

How to Create an Acrobat JavaScript If-Then Statement for PDF Forms

Steven ParkerSteven Parker Oct 28, 2026 869 views

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.

How to Write an Acrobat JavaScript If-Then Statement for Amount-Based Results
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.
Before you start

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.

Solution 1Recommended

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.

1
Open Form Properties

Right-click the destination text field in your PDF editor's Prepare Form mode and select 'Properties'.

2
Navigate to Calculations

Go to the 'Calculate' tab in the Properties window, select 'Custom calculation script', and then click the 'Edit' button.

3
Retrieve the Field Value

Start your script by retrieving the value as a number: var n = Number(this.getField("Amount").valueAsString);

4
Add Conditional Logic

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";

Implement the corrected JavaScript conditional statement
Handling Empty Fields: Checking 'if (n == 0)' at the beginning ensures that if the user leaves the amount field blank, the calculation won't incorrectly output the amortization rate.

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. 1. Open WPS PDF: Launch WPS Office and open your interactive PDF document.
  2. 2. Access Form Tools: Navigate to the Form tab or simply click on the highlighted fillable fields to input your data.
  3. 3. Save your PDF: Once completed, click 'Menu' and select 'Save As' to export your filled PDF document.
Edit, fill, and sign PDF forms seamlesslyFully compatible with standard Adobe PDF formatsLightweight, fast, and completely free to downloadIncludes Word, Excel, PowerPoint, and PDF tools in one app
microsoft office alternative - wps office

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.