PDF Editing Issues

How to Use JavaScript to Change Multiple Button Colors in PDF

Olivia MillerOlivia Miller Oct 28, 2026 869 views

Question details

The user wants to configure a PDF form so that clicking one button changes its own color as well as the colors of several related buttons simultaneously using JavaScript.

How to Use JavaScript to Change Multiple Button Colors in PDF Forms
Product
PDF Editor
Device & OS
not provided
Scenario
Customizing interactive PDF forms to provide immediate visual feedback when specific buttons are clicked by the user.
Observed behavior
The user needs a script to target multiple form fields and update their background colors simultaneously upon a click event.
Before you start

Ensure your PDF editor supports JavaScript execution in forms and that you have noted the exact field names of the buttons you intend to modify.

Solution 1Recommended

Use the fillColor Property via JavaScript

Apply a custom JavaScript action to your trigger button to dynamically change the background color of multiple fields.

You can dynamically alter the background color of any PDF form field by accessing its fillColor property via JavaScript. Note that PDF JavaScript uses a 0 to 1 scale for RGB values, not the traditional 0 to 255 scale.

1
Open form editing mode

Open your PDF document in your PDF editor and enter the Form Editing mode to reveal all interactive fields.

2
Access button properties

Right-click the button that will act as the trigger (the one the user clicks) and select Properties, then navigate to the Actions tab.

3
Add a JavaScript action

Choose 'Run a JavaScript' from the Select Action dropdown menu and click the Add button to open the script editor.

4
Input the script

Enter the script to change the target buttons' colors. For example: this.getField("TargetButton1").fillColor = ["RGB", 1, 0.65, 0]; Repeat this line for each button you want to change, replacing 'TargetButton1' with the respective field names.

5
Save and test

Click OK to save the script, exit form editing mode, and click your trigger button to test the color changes.

Use the fillColor Property via JavaScript
RGB Value Conversion: To convert standard RGB values (which range from 0 to 255) to the PDF JavaScript scale, simply divide each number by 255. For example, standard RGB(255, 165, 0) becomes ["RGB", 1, 0.65, 0].
Advanced PDF Form Editing

Easily Create and Edit Interactive PDFs with WPS Office

WPS Office provides a comprehensive PDF editor that allows you to effortlessly manage, create, and customize interactive PDF forms. Enjoy advanced form-editing capabilities in a seamless, lightweight interface.

  1. 1. Open PDF in WPS Office: Launch WPS Office and open the PDF document you wish to edit.
  2. 2. Navigate to the Form tab: Click on the 'Form' tab on the top ribbon to access a full suite of interactive form controls.
  3. 3. Add or modify buttons: Insert new push buttons, text fields, or checkboxes, and double-click them to modify their appearance and properties.
  4. 4. Save your interactive document: Once your form is fully customized, save the document to preserve all field properties and interactivity.
Create, edit, and fill interactive PDF forms quickly and easily.Fully compatible with standard PDF formats and form fields.Lightweight and optimized alternative to heavy PDF software.Cross-platform support for seamless editing on Windows, Mac, and mobile devices.
microsoft office alternative - wps office

Frequently Asked Questions

Why is my PDF JavaScript color not displaying correctly?

PDF JavaScript requires RGB values to be on a scale of 0 to 1. If you enter standard values like 255, the color will default to an incorrect shade. Ensure you divide your standard RGB values by 255 before entering them into the script.

Can I change the text color of the button using JavaScript?

Yes, you can change the text color by targeting the textColor property of the field instead of the fillColor property, using the exact same RGB array format.

How do I reset the button color back to its original state?

You can create another button or assign an additional action that sets the fillColor property to color.transparent, or manually specify the array of your original RGB values.