How to Enable or Disable PDF Form Checkboxes with JavaScript
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.

- Product
- 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.
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.
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.
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.
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'.
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.
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";`.

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. Open WPS PDF: Launch WPS Office and open your PDF document using the WPS PDF tool.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access the interactive form controls.
- 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. Edit Properties: Double-click the newly added checkbox to rename fields, adjust export values, and finalize your form structure.

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.




