PDF Editing Issues

How to Highlight Negative Numbers in PDF Forms Using JavaScript

Rana GarciaRana Garcia Nov 5, 2026 869 views

Question details

The user wants to automatically change the fill color of a PDF form field when a negative number is entered or calculated.

How to Highlight Negative Numbers in PDF Forms Using JavaScript
Product
Adobe Acrobat / PDF Forms
Device & OS
not provided
Scenario
Creating or editing an interactive PDF form that requires visual cues, such as yellow highlights, for negative financial or calculated values.
Observed behavior
The user needs the form field background to highlight in yellow when the value drops below zero, and return to transparent when the value is zero or positive.
Before you start

Ensure you have access to the PDF form in editing mode and that your PDF editor supports custom JavaScript calculations for interactive form fields.

Solution 1Recommended

Add a Custom JavaScript Calculation to the PDF Form Field

Insert a short JavaScript conditional statement to dynamically check the field's value and change its fill color automatically.

Advanced PDF forms support JavaScript to automate visual changes. By adding a simple conditional script to the calculation properties of your form field, the background color will update instantly whenever the inputted or calculated result changes.

1
Open Form Editing Mode

Open your PDF form in Adobe Acrobat and enter 'Prepare Form' mode from the tools menu.

2
Access Field Properties

Right-click the specific text field you want to modify and select 'Properties' from the context menu.

3
Navigate to the Calculate Tab

In the Properties dialog box, click on the 'Calculate' tab and select the 'Custom calculation script' option.

4
Enter the JavaScript Code

Click the 'Edit' button and paste the following code at the end of your existing script: event.target.fillColor = (event.value < 0) ? color.yellow : color.transparent;

5
Save and Test

Click 'OK', then close the properties window. Exit the form editing mode and test the field by entering a negative number to verify the yellow highlight appears.

Add a Custom JavaScript Calculation to the PDF Form Field
Script Successfully Applied: The field will now automatically highlight in yellow for negative numbers and remain transparent for positive numbers or zero.
Easy PDF Form Management

Read, Fill, and Manage PDF Forms Effortlessly with WPS Office

While advanced JavaScript creation requires specialized form-building tools, WPS Office provides a seamless and lightweight experience for opening, filling, editing, and managing interactive PDF forms.

  1. 1. Download WPS Office: Download and install the free WPS Office suite on your computer or mobile device.
  2. 2. Open Your PDF Form: Launch WPS PDF and open your interactive or calculated PDF form.
  3. 3. Fill in the Data: Click on the interactive form fields to enter your numerical data or text directly.
  4. 4. Sign the Document: Navigate to the 'Fill & Sign' tab if you need to add a secure digital signature after reviewing the calculated numbers.
  5. 5. Save and Share: Save your completed PDF form locally or export it to share with colleagues or clients.
Fully compatible with standard Adobe PDF forms and annotationsLightweight application with incredibly fast PDF rendering speedsBuilt-in tools for filling out interactive forms and signing documents securelyCross-platform support allowing you to manage PDFs on Windows, Mac, iOS, and Android
microsoft office alternative - wps office

Frequently Asked Questions

Can I use custom hex color codes instead of standard colors in Acrobat JavaScript?

Yes, you can use custom RGB or CMYK arrays instead of standard named colors like color.yellow. For example, using event.target.fillColor = ['RGB', 1, 0, 0]; would make the background pure red.

Why isn't my JavaScript calculation working in the PDF form?

Ensure that JavaScript execution is enabled in your PDF reader's security preferences. Also, check that the field's formatting isn't conflicting with the calculation script, and verify there are no syntax errors or typos in your code snippet.

Can I change the text color instead of the background fill color for negative numbers?

Absolutely. To change the text color (known as the stroke color) for negative numbers, you can modify the script to target the text property: event.target.textColor = (event.value < 0) ? color.red : color.black;

Do these JavaScript highlights work on mobile PDF readers?

Support for custom JavaScript calculations varies widely on mobile devices. While standard Adobe Acrobat Reader for mobile supports some basic scripts, many third-party or built-in PDF apps on iOS and Android may not execute the color change script properly.