How to Disable and Grey Out PDF Checkboxes Using JavaScript
Question details
The user needs a way to dynamically set a PDF checkbox field to read-only and visually grey it out based on the selection made in a corresponding radio button.

- Product
- PDF Form Editors
- Device & OS
- not provided
- Scenario
- Designing an interactive PDF form where conditional logic must dictate whether secondary checkboxes are available to the user based on their primary radio button selections.
- Observed behavior
- Without specific scripting, checkboxes remain active and clickable regardless of the radio button's state, leading to potential data entry errors by the end user.
Ensure that your PDF editing software supports JavaScript execution for form fields, and note the exact internal names of both the controlling radio button and the target checkbox.
Apply a Custom JavaScript Mouse Up Action to the Radio Button
Add a JavaScript snippet to the controlling radio button that checks its value and automatically updates the read-only status and fill color of the target checkbox.
Interactive PDF forms process logic through JavaScript triggers. By attaching a script to the 'Mouse Up' action of a radio button, the form instantly evaluates the selection the moment a user clicks. The script retrieves the checkbox field, toggles its readonly property, and alters the fill color to indicate visually that the field is disabled.
Open your PDF in Form Editing mode. Right-click the controlling radio button field and select 'Properties' from the context menu.
In the Properties dialog box, go to the 'Actions' tab. Set the 'Select Trigger' dropdown to 'Mouse Up', and choose 'Run a JavaScript' from the 'Select Action' dropdown. Click the 'Add' button.
In the JavaScript Editor, enter the following code (replace 'additionalChildCare' with your actual checkbox field name): var check = this.getField('additionalChildCare'); check.readonly = event.target.value == 'Off' ? false : true; check.fillColor = event.target.value == 'Off' ? color.white : ['G', 0.8];
Click 'OK' to close the JavaScript editor, then close the Properties dialog. Exit form editing mode and toggle the radio button to verify the checkbox dynamically changes its color and editability.

Easily View, Fill, and Manage Interactive PDF Forms with WPS Office
WPS Office includes a robust PDF toolset that allows you to easily open, fill, and interact with complex PDF forms. While designing advanced JavaScript forms is an expert-level task, processing them seamlessly is simple with WPS PDF.
- 1. Open Your PDF Form: Launch WPS Office and open your interactive PDF document from the main dashboard.
- 2. Interact with Form Fields: Navigate through the document; WPS PDF will automatically recognize interactive elements like text fields, dropdowns, and checkboxes.
- 3. Fill Out Information: Click directly into the fields to fill out your form. Conditional logic embedded in the file will execute normally.
- 4. Save or Export Securely: Once completed, click 'Save' or use the 'Export' function to generate a flattened or finalized version of your PDF.

Frequently Asked Questions
Why isn't my PDF JavaScript executing when I click the radio button?
Make sure you have attached the script to the 'Mouse Up' trigger rather than 'Mouse Down'. Additionally, verify that the field names in your script perfectly match the actual internal names of the form fields, as JavaScript is case-sensitive.
Can I apply this JavaScript to disable multiple checkboxes at once?
Yes. You can modify the script to define an array of checkbox field names, then use a 'for' loop to apply the read-only and fill color property changes to every checkbox in the array based on the single radio button selection.
Will this JavaScript functionality work in all PDF viewers?
No. While dedicated PDF editors like Adobe Acrobat and comprehensive tools support JavaScript natively, basic browser-based PDF viewers or built-in mobile readers often lack full JavaScript support, which may result in the logic failing to execute.




