PDF Editing Issues

How to Change PDF Form Field Color Based on Another Field's Value

John WilsonJohn Wilson Nov 2, 2026 869 views

Question details

The user wants to automatically change the text color of a specific PDF form field depending on whether its calculated value falls inside or outside a defined range set by other fields.

How to Change a PDF Form Field Color Based on Another Field's Value
Product
PDF Editor
Device & OS
not provided
Scenario
Creating dynamic PDF forms with conditional formatting based on field values.
Observed behavior
The form field text needs to conditionally display in different colors (e.g., red or green) according to minimum and maximum limit fields.
Before you start

Ensure you have a PDF editor that supports form field properties and custom JavaScript calculations, as basic PDF viewers cannot process complex dynamic formatting.

Solution 1Recommended

Use JavaScript for Custom Calculation in the Result Field

Apply a custom JavaScript calculation script to your result field to evaluate values dynamically and change the text color accordingly.

To achieve conditional text formatting in a PDF form, you must utilize the Calculate tab inside the field properties. By writing a simple JavaScript snippet, you can command the form to check the value of the current field against other fields (like a minimum and maximum threshold) and alter the text color based on the outcome.

1
Access field properties

Enter Form Editing mode in your PDF editor, right-click the field where the result is calculated (e.g., RESULT), and select 'Properties'.

2
Navigate to calculation settings

Click on the 'Calculate' tab located in the Text Field Properties dialog box.

3
Enter the custom script

Select 'Custom calculation script' and click the 'Edit' button. Paste your JavaScript code that calculates the value and applies the text color logic, ensuring it executes after 'event.value' is established.

Use JavaScript for Custom Calculation in the Result Field
JavaScript Example: Use the following code below your value calculation: event.target.textColor = ((event.value < Number(this.getField('ACMIN').value)) || (event.value > Number(this.getField('ACMAX').value))) ? color.red : color.green;

Create and Edit Advanced PDF Forms with WPS Office

WPS PDF provides a comprehensive set of tools for creating interactive forms, adding text fields, and managing PDF document properties smoothly and efficiently.

  1. 1. Open WPS PDF: Launch WPS Office and open your PDF document.
  2. 2. Access Form Tools: Navigate to the 'Form' tab in the top ribbon to access various form field tools.
  3. 3. Edit Form Properties: Double-click any text field to adjust its appearance, format, and calculation properties.
Easily create, edit, and fill interactive PDF formsHighly compatible with standard Adobe Acrobat PDF formatsLightweight application with an intuitive user interfaceSeamlessly manage document properties and text fields
microsoft office alternative - wps office

Frequently Asked Questions

Why isn't the JavaScript calculating automatically when I enter values?

Ensure that the calculation order is set correctly in your PDF form settings. If a dependent field calculates before the source values are inputted, the script may not trigger. Adjust the field calculation order in the form editing menu.

Can I change the background color of a PDF field instead of the text color?

Yes, you can change the background color by modifying 'event.target.fillColor' instead of 'event.target.textColor' in your custom JavaScript script.

Does conditional formatting work on all PDF viewers?

Advanced JavaScript form features might not execute on basic PDF readers (like default web browser viewers). For dynamic scripts to function correctly, users should open the document in fully-featured editors like WPS Office PDF or Adobe Acrobat.