How to Use a Checkbox to Show or Hide an Image in a PDF Form
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.

- 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.
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.
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.
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'.
Insert a Checkbox field into the document. Open its Properties dialog and navigate to the 'Actions' tab.
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; }
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 Button Fields to Toggle Icons Directly
Instead of using a separate checkbox and image field, you can use a single button field that changes its display icon when clicked.
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. Open Your PDF: Launch WPS Office and open your existing PDF document or create a new blank PDF.
- 2. Access Form Controls: Navigate to the 'Form' tab on the top ribbon to access the suite of interactive form controls.
- 3. Insert Checkboxes and Fields: Select the Checkbox or Button tool to insert the necessary interactive fields directly onto your document pages.
- 4. Configure Properties: Right-click the inserted fields to open properties and adjust behaviors, names, and visual states before saving.

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.




