PDF Editing Issues

How to Use a Checkbox to Show or Hide an Image in a PDF Form

Bushra ParveenBushra Parveen Nov 3, 2026 869 views

Question details

The user wants to configure a checkbox in an interactive PDF form so that an image appears when the box is checked and disappears when it is cleared.

How to Use a Checkbox to Show or Hide an Image in a PDF Form
Product
PDF Editor
Device & OS
not provided
Scenario
Creating an interactive PDF form where visual elements, such as instructional images or icons, depend dynamically on the user's checkbox selections.
Observed behavior
The user needs a reliable method or script to dynamically toggle the visibility state of a specific image field based on whether a checkbox is active or inactive.
Before you start

Ensure you are using a PDF editor with advanced form creation and JavaScript capabilities, and have your target image ready to be inserted as a button or image field.

Solution 1Recommended

Use JavaScript on the Checkbox Mouse Up Event

This solution uses a simple JavaScript snippet attached to the checkbox's action triggers to change the visibility property of the target image field.

To control visibility, the image should be added as a Button field configured to display an icon (your image) because standard button fields reliably support dynamic visibility changes in most PDF readers.

1
Create the Image Field

Insert a Button field into your PDF where you want the image to appear. Go to the field properties, set the layout to icon only, upload your image as the icon, and name the field exactly 'IMAGE_1'.

2
Create the Checkbox Field

Insert a Checkbox field into the document. Open its Properties dialog and navigate to the 'Actions' tab.

3
Add the JavaScript Action

Under 'Select Trigger', choose 'Mouse Up'. Under 'Select Action', choose 'Run a JavaScript', and click 'Add'. In the JavaScript editor, paste the following code: if (event.target.value == "Off") { this.getField("IMAGE_1").display = display.hidden; } else { this.getField("IMAGE_1").display = display.visible; }

4
Save and Test

Click 'OK' to close the dialogs, save your PDF document, and click the checkbox to verify that the image toggles between hidden and visible.

Use JavaScript on the Checkbox Mouse Up Event
Tip on Field Names: JavaScript in PDFs is case-sensitive. Ensure that the name 'IMAGE_1' inside the script exactly matches the name you gave to your image or button field.
Advanced PDF Form Editing

Create Interactive PDF Forms Easily with WPS Office

WPS Office features a powerful PDF editor that allows you to add text fields, checkboxes, and interactive buttons to create dynamic PDF forms without hassle.

  1. 1. Open Your PDF: Launch WPS Office and open your existing PDF document or create a new blank PDF.
  2. 2. Access Form Controls: Navigate to the 'Form' tab on the top ribbon to access the suite of interactive form controls.
  3. 3. Insert Checkboxes and Fields: Select the Checkbox or Button tool to insert the necessary interactive fields directly onto your document pages.
  4. 4. Configure Properties: Right-click the inserted fields to open properties and adjust behaviors, names, and visual states before saving.
Easily insert checkboxes, buttons, and text fields into PDFsFully compatible with standard PDF formats and Adobe Acrobat formsLightweight, fast, and user-friendly interface for all your document needsComprehensive PDF toolkit including conversion, merging, and compression
microsoft office alternative - wps office

Frequently Asked Questions

Why is the image not hiding when I uncheck the PDF checkbox?

This usually happens because the field name in the JavaScript does not perfectly match the actual field name in the PDF. Check for case sensitivity and extra spaces (e.g., 'IMAGE_1' vs 'image_1'). Also, verify that the trigger is set to 'Mouse Up' rather than 'Mouse Down'.

Can I use an actual image field instead of a button field?

Yes, but using a button field configured to display an icon (your image) is widely considered more reliable for visibility toggling in standard PDF editors, as button properties natively support interactive visibility changes better than static image fields.

Does this JavaScript work in all PDF viewers and web browsers?

No, some basic PDF viewers or built-in browser PDF readers (like Chrome or Edge) have limited or no support for PDF JavaScript. It is highly recommended that users open the interactive form in dedicated PDF software like WPS Office or Adobe Acrobat.