How to Toggle Multiple PDF Form Fields with One Button
Question details
The user wants to toggle the editable or visible state of multiple PDF form fields simultaneously using a single button.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating interactive PDF forms where a single user action needs to update the properties of several fields at once.
- Observed behavior
- The user needs a JavaScript solution to apply the exact same state change, such as turning read-only mode on or off, to multiple target fields upon clicking a form button.
Ensure you have a PDF editor that supports form creation and JavaScript execution, and that all your target form fields are already placed and uniquely named.
Toggle Read-Only Status for Multiple Fields Using JavaScript
Apply a simple JavaScript code to a button's action properties to switch multiple fields between editable and read-only states simultaneously.
This method uses a straightforward script that checks the current state of a field and reverses it. You will need to duplicate the line of code for each specific field you want to control.
In your PDF form editor, switch to form editing mode, right-click the button you want to use as the toggle, and select 'Properties'.
Navigate to the 'Actions' tab. Choose 'Mouse Up' as the trigger, select 'Run a JavaScript' from the 'Select Action' dropdown, and click 'Add'.
In the JavaScript editor, enter the following code: var f = this.getField('Text1'); f.readonly = !f.readonly; (replace 'Text1' with your actual field name).
Repeat that line of code for every field you wish to control. Click 'OK' to save the script, then close the properties window and test the button.

Toggle Field Visibility Instead of Read-Only State
If you prefer to hide the fields completely rather than just locking them, you can modify the JavaScript to toggle the display property.
Create and Manage Interactive PDF Forms with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to effortlessly design interactive forms, manage form fields, and ensure full compatibility with standard PDF readers.
- 1. Open your PDF: Launch WPS Office and open your PDF document.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to access interactive form controls.
- 3. Add a Button: Click 'Push Button' to draw a toggle button directly on your document.
- 4. Configure Field Properties: Double-click the button or target fields to adjust names, properties, and interactions seamlessly.

Frequently Asked Questions
Can I use one button to clear multiple form fields?
Yes. Instead of using JavaScript to toggle read-only states, you can use the built-in 'Reset a form' action in the button's properties. This allows you to check exactly which fields you want to clear without writing any code.
Why is my JavaScript button not working in some PDF viewers?
Not all PDF readers support JavaScript execution. Browsers' default PDF viewers or basic mobile apps often strip interactive scripts. For these features to work reliably, users should open the form in fully-featured PDF software like Adobe Acrobat or WPS PDF.
How do I find the exact names of my form fields?
In your PDF form editor, open the form field pane or right-click a field and select 'Properties'. The exact field name will be prominently displayed in the 'General' tab.




