PDF Editing Issues

How to Use JavaScript to Show and Hide Multiple Checkboxes in a PDF Form

Bushra ParveenBushra Parveen Nov 3, 2026 869 views

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.
Before you start

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.

Solution 1Recommended

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.

1
Open Checkbox Properties

Enter Form Editing mode in your PDF editor. Right-click the primary checkbox (the trigger) and select 'Properties' from the context menu.

2
Set the Action Trigger

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.

3
Insert the JavaScript Code

In the JavaScript Editor window, type the following code: var nHide = event.target.isBoxChecked(0) ? display.visible : display.hidden; this.getField("TargetFieldName").display = nHide;

4
Add Multiple Fields

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;).

Test Your Form: After saving the script, exit Form Editing mode and click the primary checkbox to verify that the target fields appear and disappear as expected.

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. 1. Open WPS Office: Launch WPS Office on your device and navigate to the PDF tab.
  2. 2. Load Your PDF Form: Open the interactive PDF file containing your checkboxes and text fields.
  3. 3. Edit and Fill Fields: Access the Form tools to fill out the document, toggle checkboxes, or edit text securely.
  4. 4. Save the Document: Click 'Save' to retain your form inputs and preserve the interactive elements of the PDF.
Easily fill, manage, and edit interactive PDF form fieldsHighly compatible with standard Adobe Acrobat PDF formatsLightweight, fast, and features an intuitive user interface
microsoft office alternative - wps office

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.