How to Fix Acrobat PDF Field Color Scripts Failing Above 99,999
Question details
The user needs to fix a PDF form field color script that evaluates large values incorrectly due to string-based comparison instead of numeric comparison.

- Product
- Adobe Acrobat PDF
- Device & OS
- not provided
- Scenario
- Using JavaScript to dynamically change the fill or text color of PDF form fields based on the inputted value.
- Observed behavior
- The script produces incorrect color results for values larger than 99,999 because event.value is treated as text rather than a mathematical number.
Before editing your form scripts, make sure your PDF is not restricted by security settings and that you have a basic understanding of the Adobe Acrobat JavaScript editor.
Convert Field Value to a Number Before Comparison
Use the unary plus operator or JavaScript Number functions to ensure the field value is evaluated mathematically rather than alphabetically.
When comparing values in Adobe Acrobat PDF scripts, the `event.value` property is generally returned as a string (text). In a text comparison, '100000' is considered smaller than '26000' because the character '1' is less than '2'.
By coercing the string to a number, you ensure that Acrobat evaluates the actual mathematical quantity before applying conditional formatting.
Open your PDF document in Adobe Acrobat, navigate to the 'Prepare Form' tool, right-click the specific form field you want to modify, and select 'Properties'.
Go to the 'Calculate' or 'Format' tab where your custom JavaScript is currently applied, and click 'Edit' to open the JavaScript editor.
Modify your script to use the unary plus operator (+) before event.value. For example, use `if (+event.value > 26000)` instead of `if (event.value > 26000)`.
Set your color preferences inside the conditional statement. Example: `event.target.textColor = color.black; if (+event.value > 26000) event.target.fillColor = color.green; else event.target.fillColor = color.red;`
Ensure you strip out any commas, currency symbols, or blank spaces before running the number conversion so the script doesn't produce a NaN (Not-a-Number) error.

Easily Manage and Fill PDF Forms with WPS Office
If you frequently struggle with complex PDF scripts in Adobe Acrobat, try WPS Office. Its built-in PDF editor provides intuitive form filling, document conversion, and editing tools without the steep learning curve.
- 1. Download and Install: Download WPS Office Free from the official website and install it on your computer or mobile device.
- 2. Open Your PDF: Launch WPS Office, select the 'PDF' tab on the home screen, and open your document.
- 3. Edit Forms Easily: Navigate to the Form or Edit tab to effortlessly fill out, modify, read, or print your PDF document.

Frequently Asked Questions
Why does my PDF script think 100,000 is less than 26,000?
When numbers are stored as text (strings), JavaScript compares them alphabetically based on the first character. The character '1' in '100000' is evaluated as smaller than the '2' in '26000'. Converting the field value to a number resolves this issue.
How do I remove commas from an Acrobat PDF field value before calculating?
You can use the JavaScript replace() function. For example, `event.value.toString().replace(/,/g, '')` will strip all commas from the string, allowing it to be safely converted into a numeric value.
Does WPS Office support filling out interactive PDF forms?
Yes, the built-in PDF editor in WPS Office fully supports interactive PDF form filling, allowing you to easily type, select checkboxes, and save your completed forms without needing complex third-party scripts.




