PDF Editing Issues

How to Fix Acrobat JavaScript If-Else Conditions for Text Fields

Huma Ashraf ChHuma Ashraf Ch Oct 28, 2026 868 views

Question details

The user needs to fix a PDF form script where if-else conditions comparing text fields ('Thin' or 'Thick') and month fields produce undefined or incorrect results.

How to Fix Acrobat JavaScript If-Else Conditions for Text Fields
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Calculating a numerical value in a PDF form using custom JavaScript based on the inputs from a months field and a thickness text field.
Observed behavior
The JavaScript comparisons produce undefined or incorrect results due to improper string comparison, data type mismatches, or missing boundary checks in the if-else logic.
Before you start

Before modifying your JavaScript form code, ensure you save a backup copy of your PDF file to prevent accidental loss of complex logic or formatting.

Solution 1Recommended

Normalize String Cases and Explicitly Convert Numeric Fields

Fix logic errors by forcing numeric fields into Number types and normalizing text fields to upper or lower case before checking conditions.

In JavaScript, comparing a number stored as a string against an actual integer can yield unexpected results. Similarly, text fields are case-sensitive. Standardizing the formatting immediately upon retrieval ensures your if-else conditions evaluate accurately.

1
Retrieve and convert numeric fields

Wrap your numeric field extraction in the Number() function to ensure it evaluates as an integer. For example: var n = Number(this.getField('Months').valueAsString);

2
Normalize the text field values

Use valueAsString to read the text field and append .toUpperCase() to standardize the string case. For example: var c = this.getField('Thickness').valueAsString.toUpperCase();

3
Update the condition checks

Compare the normalized text with exact quoted uppercase strings like 'THIN' or 'THICK'. Ensure you use correct mathematical operators for numeric ranges without omitting numbers like 11 or 17.

4
Add an error-catching Else statement

End your if-else block with a final else condition, such as else { event.value = 'ERROR'; }, to easily identify when an input does not meet any of your specified conditions.

Normalize String Cases and Explicitly Convert Numeric Fields
Testing your changes: After updating the script, test the form using edge case values (like exactly 11 or 17 months, and uncapitalized 'thin') to verify your logic captures all ranges and inputs correctly.
WPS PDF Editor

Easily Fill and Manage PDF Forms with WPS Office

If you are looking for a reliable, fast, and user-friendly tool to handle your PDF forms, WPS PDF provides a comprehensive set of features for filling, editing, and managing your documents without complex scripting.

  1. 1. Open your PDF: Launch WPS Office and open your interactive PDF form.
  2. 2. Interact with the form: Click directly on the highlighted text fields, checkboxes, or dropdowns to input your data.
  3. 3. Save your filled document: Once completed, click 'Menu' and select 'Save' or 'Save As' to preserve your inputs securely.
Effortlessly fill out and manage interactive PDF formsHighly compatible with standard Adobe Acrobat PDF formatsLightweight application that won't slow down your deviceCross-platform support for seamless workflow across PC and mobile
microsoft office alternative - wps office

Frequently Asked Questions

Why is my Acrobat JavaScript returning 'undefined'?

This commonly happens when a script attempts to read a field that is empty, or references a field name incorrectly. Using .valueAsString ensures you retrieve an empty string instead of an undefined object if the field is left blank.

How do I make text comparison case-insensitive in PDF JavaScript?

You can temporarily convert the field value to all uppercase or all lowercase using .toUpperCase() or .toLowerCase() before comparing it with a capitalized or lowercase string in your if-else statement.

Why are my greater-than and less-than ranges failing in Acrobat forms?

Numeric ranges often fail if the field value is read as a string. Wrapping your field extraction in Number() explicitly casts it as an integer or float, allowing mathematical operators like < and > to function correctly.