PDF Editing Issues

How to Cycle an Acrobat Button Through Multiple Colors with JavaScript

Huda QurayshiHuda Qurayshi Nov 3, 2026 869 views

Question details

The user wants to configure a button in a PDF document to cycle through more than two colors (such as red, green, yellow, and blue) when clicked to represent various status levels.

How to Cycle an Acrobat Button Through Multiple Colors with JavaScript
Product
Adobe Acrobat Pro
Device & OS
not provided
Scenario
Creating an interactive PDF form where a button's background color changes sequentially to indicate different workflow states upon consecutive clicks.
Observed behavior
The button currently only switches back and forth between two colors using a simple toggle condition, but fails to cycle through an extended sequence of multiple colors.
Before you start

Ensure your PDF editor supports JavaScript for interactive forms and that you have the form fields panel open. Basic familiarity with adding custom mouse actions to PDF buttons is required.

Solution 1Recommended

Use Conditional JavaScript with color.equal to Cycle Colors

Implement a custom JavaScript action that checks the button's current background color and selectively updates it to the next color in your predefined sequence.

Instead of a simple boolean toggle, you must evaluate the current 'fillColor' of the button and conditionally apply the next color. Because colors in Acrobat JavaScript are represented as arrays, standard equality operators (like ==) will not work. You must use Acrobat's built-in 'color.equal' method to accurately compare color arrays.

1
Enter Form Editing Mode

Open your PDF in Acrobat Pro, navigate to the Tools menu, and select 'Prepare Form' to enable form editing.

2
Access Button Properties

Right-click the target button you want to modify, select 'Properties' from the context menu, and navigate to the 'Actions' tab.

3
Add a JavaScript Action

In the 'Select Trigger' dropdown, choose 'Mouse Up'. In the 'Select Action' dropdown, choose 'Run a JavaScript', then click the 'Add' button.

4
Write the Sequence Script

In the JavaScript Editor window, write an if/else if sequence using color.equal. For example: if (color.equal(event.target.fillColor, color.blue)) { event.target.fillColor = color.green; } else if (color.equal(event.target.fillColor, color.green)) { event.target.fillColor = color.yellow; } else { event.target.fillColor = color.blue; }. Click 'OK' to save.

Use Conditional JavaScript with color.equal to Cycle Colors
Custom Color Arrays: You are not limited to predefined colors like color.red or color.blue. You can define custom colors using arrays, such as ["RGB", 0.5, 0, 1] for purple, and use those in your cycle logic.
WPS PDF Editor

Easily Create Interactive PDF Forms with WPS Office

While advanced JavaScript programming can be complex, WPS PDF provides a user-friendly interface to build interactive forms. You can achieve excellent status-indicating results using drop-down lists and standardized form controls without writing a single line of code.

  1. 1. Open your PDF in WPS: Launch WPS Office and open your existing PDF document using the built-in WPS PDF tool.
  2. 2. Navigate to the Form Tab: Select the 'Form' tab on the top ribbon to access the interactive form field creation tools.
  3. 3. Insert a Drop-Down List: Click the 'Combo Box' or 'Drop-down' icon, then click and drag on the document to place the field where your status indicator should be.
  4. 4. Configure Status Values: Double-click the new form field to open its Properties dialog. Add your various status names (e.g., Pending, Approved, Denied) as list items and save.
Free and lightweight PDF editing suiteCreate functional status indicators without complex JavaScriptFully compatible with Microsoft Word, Excel, and PowerPoint formats, as well as standard PDFsIntuitive drag-and-drop form building interface
microsoft office alternative - wps office

Frequently Asked Questions

Why doesn't a simple true/false script work for more than two button colors?

A boolean (true/false) toggle can only alternate between two specific states. To cycle through three or more colors, you must evaluate the current color against all possible states using conditional logic (like if/else if) to determine and assign the correct next color in the sequence.

Can I change the button's text label along with its background color?

Yes. Within the same JavaScript action, you can update the button's text by assigning a new string using the event.target.buttonSetCaption("New Status Text") method right after the fillColor assignment.

What should I set as the default color for the button?

You should set the button's default fill color in the 'Appearance' tab of the Button Properties to match the very first color evaluated in your JavaScript's 'if' sequence. This ensures the cycle begins predictably on the first click.