PDF Editing Issues

How to Enable or Disable PDF Form Checkboxes with JavaScript

Steven ParkerSteven Parker Nov 5, 2026 869 views

Question details

The user needs to control the editability of dependent checkboxes (A, B, and C) based on the selection of a primary Yes/No checkbox in a PDF form.

How to Enable or Disable PDF Form Checkboxes with JavaScript
Product
PDF
Device & OS
not provided
Scenario
Creating an interactive PDF form with conditional logic where user input dynamically updates other form fields.
Observed behavior
When 'Yes' is selected, related fields should become editable. When 'No' is selected, the related fields must be cleared of any data and disabled from further editing.
Before you start

Ensure your PDF editing software supports JavaScript for interactive forms and that you have identified the exact field names of all the checkboxes involved in your document.

Solution 1Recommended

Configure Checkboxes and Apply Custom JavaScript

Set up the Yes and No checkboxes as a mutually exclusive group and apply a custom JavaScript action to control the readonly status and values of the dependent fields.

By assigning the exact same field name to both the Yes and No checkboxes but giving them different export values, they will behave like mutually exclusive radio buttons. You can then attach a mouse action to this group that triggers a JavaScript script to manage the dependent fields.

1
Group the Yes and No checkboxes

Open your PDF editor's form builder. Select the Yes checkbox and open its properties. Assign it a field name, such as 'ToggleStatus'. Do the exact same for the No checkbox so they share the identical field name.

2
Set distinct export values

In the properties of the Yes checkbox, navigate to the Options tab and set the export value to 'Yes'. For the No checkbox, set its export value to 'No'.

3
Add an action script

Right-click the Yes/No checkbox group, select Properties, and go to the Actions tab. Choose 'Mouse Up' as the trigger and 'Run a JavaScript' as the action, then click Add.

4
Enter the JavaScript code

Input the script to check the value of 'ToggleStatus'. Use an if/else statement: if the value is 'Yes', use `this.getField("FieldA").readonly = false;` (repeat for Fields B and C). If the value is 'No', set `.readonly = true;` and clear them using `.value = "Off";`.

Configure Checkboxes and Apply Custom JavaScript
JavaScript Case Sensitivity: Make sure the field names referenced in your JavaScript exactly match the names defined in your PDF form properties. JavaScript is case-sensitive, so 'fieldA' and 'FieldA' will be treated differently.
Edit Interactive PDFs with WPS

Create and Manage PDF Forms in WPS Office

WPS PDF provides a comprehensive and user-friendly set of tools for creating, editing, and filling interactive PDF forms. You can easily manage checkboxes, text fields, and document properties without needing heavy, complex software.

  1. 1. Open WPS PDF: Launch WPS Office and open your PDF document using the WPS PDF tool.
  2. 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access the interactive form controls.
  3. 3. Insert Form Fields: Click on the 'Check Box' or 'Text Field' tool and click anywhere on the document page to insert a new form element.
  4. 4. Edit Properties: Double-click the newly added checkbox to rename fields, adjust export values, and finalize your form structure.
Easily add, delete, and configure PDF form fields like checkboxes, radio buttons, and text boxes.Fully compatible with standard PDF forms created in Adobe Acrobat and Microsoft Office tools.Lightweight alternative to heavy PDF editors with a simple, familiar user interface.Seamlessly edit PDF text, images, and pages directly within the same application.
microsoft office alternative - wps office

Frequently Asked Questions

Why aren't my dependent checkboxes clearing when I select 'No'?

This usually happens if the JavaScript only disables the fields but does not explicitly reset their values. Ensure you have a line of code like `this.getField("FieldA").value = "Off";` within the 'No' condition of your script.

Can I use radio buttons instead of checkboxes for Yes and No?

Yes. Radio buttons are naturally mutually exclusive and are highly recommended for binary choices like Yes/No. You can apply the exact same JavaScript logic to the radio button group's Actions tab.

Does the JavaScript run automatically when opening the PDF?

No, the JavaScript described in this solution is triggered by a specific user interaction, such as a 'Mouse Up' event (clicking the checkbox). It only evaluates and executes when the user actively interacts with the Yes/No field.

Why do my Yes and No checkboxes get checked at the same time?

If your Yes and No checkboxes can be checked simultaneously, they likely have different field names. To make them mutually exclusive like radio buttons, they must share the exact same field name but have distinct export values.