How to Use JavaScript to Show and Hide Multiple Checkboxes in a PDF Form
Question details
The user needs to dynamically display or hide multiple checkboxes and text fields in a PDF form whenever another specific checkbox is selected by the reader.
- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where certain secondary fields only appear if a primary conditional checkbox is checked.
- Observed behavior
- The user wants to configure the visibility properties of multiple form fields simultaneously using JavaScript without affecting unrelated form elements.
Ensure you are using a professional PDF editor that supports form creation and custom JavaScript execution. Make a note of the exact 'Name' properties of all the fields you intend to show or hide.
Apply a Visibility JavaScript to the Trigger Checkbox
Use a custom JavaScript action on the primary checkbox to toggle the display properties of your target text fields and secondary checkboxes.
Interactive PDF forms rely on simple JavaScript actions triggered by mouse events. By applying a visibility script to the main checkbox's 'Mouse Up' action, you can instantly alter the display status of any other named field in the document.
Enter Form Editing mode in your PDF editor. Right-click the primary checkbox (the trigger) and select 'Properties' from the context menu.
Navigate to the 'Actions' tab. From the 'Select Trigger' dropdown menu, choose 'Mouse Up'. From the 'Select Action' dropdown menu, choose 'Run a JavaScript', and then click the 'Add' button.
In the JavaScript Editor window, type the following code: var nHide = event.target.isBoxChecked(0) ? display.visible : display.hidden; this.getField("TargetFieldName").display = nHide;
To hide or show more than one field simultaneously, simply duplicate the last line of the code for each field. Replace "TargetFieldName" with the exact names of your other text fields or checkboxes (e.g., this.getField("AddressField").display = nHide;).
Create and Manage Interactive PDFs with WPS Office
WPS Office features a robust built-in PDF Editor that lets you seamlessly manage interactive forms, fill out checkboxes, and edit complex documents. It is an all-in-one productivity suite designed to handle your PDF requirements effortlessly.
- 1. Open WPS Office: Launch WPS Office on your device and navigate to the PDF tab.
- 2. Load Your PDF Form: Open the interactive PDF file containing your checkboxes and text fields.
- 3. Edit and Fill Fields: Access the Form tools to fill out the document, toggle checkboxes, or edit text securely.
- 4. Save the Document: Click 'Save' to retain your form inputs and preserve the interactive elements of the PDF.

Frequently Asked Questions
Can I use JavaScript to set field values instead of just changing visibility?
Yes, you can modify your JavaScript to alter the value of a field rather than its visibility. Use the code this.getField("FieldName").value = "Your Desired Text"; within your conditional statement.
Why isn't my JavaScript working when someone opens my PDF?
The user might be viewing the PDF in a basic browser viewer or a lightweight reader that disables or does not support JavaScript execution. Advise your users to open the form in a fully-featured PDF editor or viewer to ensure interactive scripts run properly.
How do I find the exact name of a form field to use in my script?
In your PDF editor's form preparation mode, right-click the specific text field or checkbox and choose 'Properties'. The exact identifier you need for your JavaScript will be listed under the 'Name' text box in the General tab.




