PDF Editing Issues

How to Create a Toggle Color Button in Acrobat PDF

Emma BrownEmma Brown Nov 5, 2026 868 views

Question details

The user wants to configure a button in a PDF form that dynamically toggles its background fill color between yellow and red every time it is clicked.

How to Make a PDF Button Alternate Colors on Click in Adobe Acrobat
Product
Adobe Acrobat PDF
Device & OS
not provided
Scenario
Adding interactive elements to a PDF form to visually indicate button states using JavaScript.
Observed behavior
The button needs to change its background color to the opposite color (yellow to red, or red to yellow) on the Mouse Up event, and a text field requires inverse RGB colors based on numeric values.
Before you start

Ensure you have the 'Prepare Form' tool enabled in Adobe Acrobat and that JavaScript execution is permitted in your PDF viewer's security preferences.

Solution 1Recommended

Add JavaScript to Toggle Colors on Mouse Up

Use this solution to directly apply a conditional color-changing script to the button's click event.

Acrobat allows you to attach custom JavaScript snippets to form fields. By using a simple ternary operator in the Mouse Up event, the button can evaluate its current fill color and switch to the alternative color.

1
Open the Prepare Form tool

Launch your document in Adobe Acrobat, navigate to 'Tools', and select 'Prepare Form' to enter form editing mode.

2
Access Button Properties

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

3
Set up the JavaScript Action

Go to the 'Actions' tab. Select 'Mouse Up' in the Select Trigger dropdown menu, choose 'Run a JavaScript' in the Select Action menu, and click the 'Add...' button.

4
Input the Script

In the JavaScript Editor, type or paste the following code: event.target.fillColor = color.equal(color.yellow, event.target.fillColor) ? color.red : color.yellow; Click 'OK' to save.

Add JavaScript to Toggle Colors on Mouse Up
Testing the Button: Exit 'Prepare Form' mode by clicking 'Preview' in the top right corner. Click your button multiple times to verify that it seamlessly alternates between yellow and red.
Edit PDF Forms Easily

Manage and Fill Interactive PDF Forms with WPS Office

WPS Office provides a highly compatible and lightweight PDF editor. It easily opens and allows you to fill out interactive PDF forms without requiring expensive premium software, providing a smooth user experience.

  1. 1. Download WPS Office: Download and install the free WPS Office suite from the official website.
  2. 2. Open Your Interactive PDF: Launch WPS PDF and open your interactive PDF document containing the dynamic form buttons.
  3. 3. Fill and Manage the Form: Navigate to the 'Form' tab to interact with the fields, click buttons, and view dynamic color changes smoothly.
Fully compatible with Adobe Acrobat PDF formats and form structures.Easily view, fill, and interact with dynamic PDF forms.Lightweight software that loads large interactive PDFs quickly.Comprehensive built-in tools for adding text, images, and signatures.
microsoft office alternative - wps office

Frequently Asked Questions

Can I use colors other than yellow and red for my PDF button?

Yes, Adobe Acrobat JavaScript supports several predefined colors such as color.blue, color.green, color.black, and color.white. You can replace color.yellow and color.red in your script with any of these predefined options.

Why isn't my JavaScript button changing colors when I click it?

This usually happens if you are still in 'Prepare Form' editing mode. You must switch to 'Preview' mode or close the form editing tools to interact with the button. Additionally, check that JavaScript is enabled in your PDF viewer's preferences.

How do I define a custom RGB color in Acrobat JavaScript?

A custom RGB color is defined as an array where the first element is the color space ('RGB') followed by three normalized values between 0 and 1. For example, a custom purple would be defined as ['RGB', 0.5, 0, 0.5].

Will this JavaScript color toggle work in all PDF viewers?

No, not all third-party PDF viewers or web browser PDF plugins support Acrobat JavaScript actions. For the scripts to work as intended, the document should be opened in robust PDF applications like Adobe Acrobat or highly compatible readers.