PDF Editing Issues

How to Toggle Between Two Button Icons in a PDF Form

Bushra ParveenBushra Parveen Nov 3, 2026 868 views

Question details

The user wants to cycle between two different icons within a single PDF button field without relying on multiple buttons or document layers.

How to Toggle Between Two Button Icons in a PDF Form
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Creating dynamic and interactive PDF forms with a single button that changes its visual icon upon user interaction.
Observed behavior
The goal is to dynamically switch the icon of a single button field using JavaScript to extract and set the icon from hidden fields.
Before you start

Ensure you have access to a PDF editor that supports advanced form field creation and JavaScript execution, and prepare the two image files you intend to use as icons.

Solution 1Recommended

Use Hidden Button Fields and JavaScript

Store your target icons in hidden fields and use a JavaScript mouse-up event to swap them seamlessly.

This method avoids the complexity of layering and keeps your document structure clean by leveraging built-in JavaScript methods to get and set button icons dynamically.

1
Create Hidden Button Fields

Add two button fields to your PDF form (e.g., 'IconA' and 'IconB'). In their properties, set their layout to 'Icon only', import your desired images for each, and set their visibility to 'Hidden'.

2
Create the Main Interactive Button

Draw the main visible button field where the user will click to toggle the icons.

3
Add a JavaScript Action

Open the properties of the main button, navigate to the Actions tab, and set the trigger to 'Mouse Up'. Choose 'Run a JavaScript' from the action dropdown and click 'Add'.

4
Write the Toggle Script

Input a script that checks the current icon state using buttonGetIcon() and swaps it using buttonSetIcon(). For example: event.target.buttonSetIcon(this.getField('IconA').buttonGetIcon());

Use Hidden Button Fields and JavaScript
Script Accuracy: Ensure the field names in your JavaScript perfectly match the hidden button field names you created, and remember that JavaScript functionality may be limited in some basic web-based PDF viewers.
Advanced PDF Form Editing

Create and Edit Interactive PDF Forms with WPS Office

WPS Office provides a comprehensive PDF editor that allows you to seamlessly create, manage, and fill interactive PDF forms without complex setups.

  1. 1. Open your PDF: Launch WPS Office and navigate to the PDF tab. Click on 'Open' to load your existing PDF document.
  2. 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access interactive form controls.
  3. 3. Add Interactive Fields: Select the desired field type, such as a Push Button, and draw it directly onto your document layout.
  4. 4. Configure Properties: Double-click the new field to open the properties panel, where you can easily customize its appearance, icons, and actions.
Easily add and customize interactive form fields like buttons and checkboxesFully compatible with standard PDF forms and Adobe Acrobat filesLightweight application with a highly intuitive user interfaceSupports cross-device PDF editing, reading, and syncing
microsoft office alternative - wps office

Frequently Asked Questions

Can I use standard images for PDF button icons?

Yes, you can import standard image formats like JPEG, PNG, or even other PDF pages to set as your button icon in most professional PDF editors.

Do I need to know JavaScript to create PDF forms?

Basic forms with text fields, dropdowns, and checkboxes do not require JavaScript. However, advanced interactive features like toggling icons dynamically usually require simple scripting.

Why are my PDF form buttons not working?

Interactive form buttons require a PDF viewer that supports interactive forms and JavaScript. Ensure your users are opening the file in a compatible desktop PDF reader rather than a basic browser viewer.

Can I hide fields in a PDF form?

Yes, in the field properties under the General tab, you can set the visibility status to 'Hidden'. This is commonly used to store data or icons needed by scripts without cluttering the page layout.