How to Show or Hide PDF Form Fields When a Checkbox is Selected
Question details
The user wants to configure a PDF form so that specific fields dynamically appear or hide based on whether a checkbox is selected.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating interactive and conditional PDF forms where certain sections or questions are optional.
- Observed behavior
- Additional form fields need to become visible when a checkbox is checked and hidden when it is cleared.
Ensure you are using a PDF editor that supports form field creation and JavaScript execution, such as Adobe Acrobat Pro or compatible professional PDF editing software.
Use JavaScript to Control Field Visibility via Checkbox
Add a custom Mouse Up script to the checkbox to dynamically change the display property of the target fields.
PDF forms support JavaScript to add interactive logic. By adding a simple script to a checkbox's action triggers, you can control whether other fields (like text boxes or dropdowns) are visible or hidden depending on the checkbox's state.
Open your PDF editor, enter form editing mode, and create both the trigger checkbox and the target text fields or sections you want to control.
Right-click the newly created checkbox and select 'Properties' from the context menu.
Navigate to the 'Actions' tab. Select 'Mouse Up' from the Select Trigger dropdown menu, choose 'Run a JavaScript' from the Select Action menu, and then click 'Add'.
In the JavaScript editor, input the following code: this.getField('TargetFieldName').display = event.target.value !== 'Off' ? display.visible : display.hidden; Replace 'TargetFieldName' with the exact name of the field you want to hide or show.
Click 'OK' to save the script, close the properties dialog, and exit form editing mode. Test the form by checking and unchecking the box to ensure the target field appears and disappears correctly.

Edit and Manage PDF Forms Easily with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to read, fill, edit, and manage interactive PDF forms effortlessly.
- 1. Download and Install: Download WPS Office from the official website and install it on your computer or mobile device.
- 2. Open Your PDF Form: Launch WPS Office, click 'Open', and select your interactive PDF file.
- 3. Fill and Edit: Navigate to the 'Fill & Sign' or 'Form' tabs to interact with checkboxes, text fields, and conditional elements seamlessly.
- 4. Save and Export: Once completed, click the 'Save' icon or export the document to share it with others.

Frequently Asked Questions
Why isn't my PDF JavaScript working when I click the checkbox?
Ensure that the field name referenced in your script exactly matches the target field's name, including capitalization. Additionally, verify that JavaScript execution is enabled in your PDF reader's security preferences (usually found under Edit > Preferences > JavaScript).
Can I hide multiple fields with one checkbox?
Yes. You can repeat the this.getField('FieldName').display line of code in the same JavaScript window for each field you wish to hide or show, simply changing the 'FieldName' for each line.
Will conditional PDF form fields work on mobile devices?
Support for PDF JavaScript varies on mobile devices. While desktop applications like Adobe Acrobat or WPS Office can execute these scripts reliably, many default mobile PDF viewers or web browsers may not fully support interactive JavaScript features.




