How to Toggle Read-Only Fields Using PDF JavaScript
Question details
The user needs to dynamically enable or disable the 'Read Only' property of checkboxes and text fields in an interactive PDF form depending on which radio button is selected.

- Product
- Device & OS
- not provided
- Scenario
- Creating interactive PDF forms with conditional field logic.
- Observed behavior
- Dynamic field interactivity requires correctly writing and assigning JavaScript actions to conditional form elements.
Make sure you have access to a PDF editor that supports JavaScript form actions, and take note of the exact field names for your radio buttons, checkboxes, and text boxes within the document properties.
Configure JavaScript for Radio Buttons and Checkboxes
Apply specific JavaScript action scripts using the 'Mouse Up' trigger to control the read-only status dynamically when a user interacts with the form.
In PDF forms, JavaScript behaviors are usually triggered by user interactions. Using the 'Mouse Up' event ensures that the action executes only after the user fully completes the click, making it the most reliable trigger for conditional logic.
Open your PDF form in editing mode. Right-click the controlling Radio Button (e.g., Radio Button 'D') and select 'Properties' from the context menu.
Navigate to the 'Actions' tab in the Properties window. Select 'Mouse Up' from the Select Trigger dropdown, and choose 'Run a JavaScript' from the Select Action list. Click 'Add'.
In the JavaScript Editor, enter the script to disable read-only mode for your checkboxes: `this.getField("Checkbox 1").readonly = false; this.getField("Checkbox 2").readonly = false;` Click 'OK' to save.
Now, right-click the target Checkboxes in your form, select 'Properties', and navigate to the 'Actions' tab. Again, select 'Mouse Up' and 'Run a JavaScript'.
Enter the script to enable the dependent text field: `this.getField("Textbox 1").readonly = false;` Click 'OK' and test your form in preview mode.

Manage and Fill Interactive PDFs with WPS Office
WPS Office offers a comprehensive PDF toolkit to help you view, manage, and seamlessly fill out interactive PDF forms. Handling standard form fields like checkboxes, radio buttons, and text fields is simple and highly efficient with WPS PDF.
- 1. Launch WPS Office: Open the WPS Office suite on your device and click on the 'PDF' tab on the main dashboard.
- 2. Open Your Interactive Form: Browse and select your interactive PDF file to open it directly in the WPS PDF viewer.
- 3. Interact with Fields: Use your mouse to click on radio buttons and checkboxes. The form will dynamically respond based on its embedded logic.
- 4. Save or Export: Once your form is completely filled out, click the 'Save' icon or export the document securely.

Frequently Asked Questions
Why doesn't the JavaScript trigger when I click the radio button?
Ensure you have selected the 'Mouse Up' trigger instead of 'Mouse Down'. 'Mouse Up' ensures the script runs only after the user has completely released the mouse click, which is the standard way to confirm a form selection.
How do I change the field back to read-only if another radio button is selected?
You need to add a corresponding JavaScript action to the other radio buttons. Open the properties of the alternative radio buttons, add a 'Mouse Up' action, and use the script `this.getField("Checkbox 1").readonly = true;` to lock the fields again.
Do these JavaScript actions work in all PDF viewers?
Not all PDF viewers or web browsers support embedded JavaScript. For the best compatibility and functionality, users should open the interactive PDF in full-featured desktop PDF software like WPS Office or Adobe Acrobat.




