How to Use Acrobat JavaScript to Show and Hide PDF Fields with a Checkbox
Question details
The user needs to dynamically toggle the visibility of specific PDF form fields based on whether a checkbox is checked or unchecked.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating interactive PDF forms that require dynamic fields depending on user input.
- Observed behavior
- One form field needs to become visible while another is hidden when a checkbox is selected, and this behavior must reverse when the checkbox is cleared.
Ensure your PDF is opened in form editing mode (such as Prepare Form in Acrobat) and that you know the exact field names of the checkbox and the fields you intend to hide or show.
Use Acrobat JavaScript to Toggle Field Display Properties
Attach a custom JavaScript action to the checkbox that reads its value and updates the display property of the target fields.
By applying a custom script to the 'Mouse Up' action of a checkbox, you can evaluate whether the checkbox is checked (typically returning an export value like 'Yes') or cleared (returning 'Off'). The script then modifies the 'display' property of the target text fields accordingly.
Right-click the target checkbox in form editing mode and select 'Properties' from the context menu.
Navigate to the 'Actions' tab. Choose 'Mouse Up' as the Select Trigger, choose 'Run a JavaScript' as the Select Action, and click the 'Add' button.
In the JavaScript Editor, paste the following code (update the field names to match your form): var cb = this.getField("YourCheckboxName").value; if (cb !== "Off") { this.getField("FieldToHide").display = display.hidden; this.getField("FieldToShow").display = display.visible; } else { this.getField("FieldToHide").display = display.visible; this.getField("FieldToShow").display = display.hidden; }
Click 'OK' to save the script, close the properties dialog, and exit form editing mode to test checking and unchecking the box.

Manage and Fill PDF Forms Easily with WPS Office
While advanced JavaScript programming is specific to Adobe Acrobat, WPS Office provides a lightweight, fast, and free alternative for viewing, filling out, and editing standard PDF forms, fully integrated with a complete Office suite.
- 1. Download WPS Office: Visit the official WPS website to download and install WPS Office for free on your device.
- 2. Open Your PDF Form: Launch the application and drag your PDF document into the workspace.
- 3. Fill and Edit: Use the integrated PDF tools to fill form fields, add annotations, or modify text seamlessly.

Frequently Asked Questions
Why is my Acrobat JavaScript not running when I click the checkbox?
This typically occurs if the JavaScript is attached to the wrong trigger (such as 'Mouse Down' instead of 'Mouse Up') or if executing JavaScript is disabled in your PDF viewer's security preferences.
How do I find the exact name of a PDF form field?
Enter form editing mode (e.g., Prepare Form in Acrobat), right-click the field, and select 'Properties'. The exact field name will be displayed under the 'General' tab.
Can I use this script to hide multiple fields at once?
Yes. You can hide or show multiple fields by adding additional lines for each field within the same if/else block, such as adding 'this.getField("AnotherField").display = display.hidden;'.
What happens if a user opens the PDF in a browser instead of a dedicated PDF reader?
Many built-in web browser PDF viewers do not fully support Acrobat JavaScript. For dynamic features like showing and hiding fields to work reliably, the form should be opened in a dedicated PDF application.




