How to Lock and Unlock PDF Form Fields Using Acrobat Button Scripts
Question details
The user needs to know how to create an Acrobat button script using JavaScript to toggle PDF form fields between locked (read-only) and unlocked states, while updating the button's caption.

- Product
- Adobe Acrobat DC
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where users or administrators can lock or unlock specific input fields by clicking a dedicated button.
- Observed behavior
- The user wants the correct JavaScript code and implementation method to change the read-only properties of specific fields and utilize the buttonSetCaption method correctly.
Make sure you have a backup of your PDF form and accurately note down the exact names of the form fields you intend to lock or unlock, as Acrobat JavaScript is highly case-sensitive.
Use Acrobat JavaScript to Toggle Field States and Button Captions
Add a custom JavaScript action to a PDF button that checks the current state of a form field, toggles its read-only property, and updates the button text accordingly.
In Adobe Acrobat DC, you can use the 'Run a JavaScript' action to manipulate form fields. By accessing the target field via 'this.getField()', you can modify its 'readonly' property. The 'event.target.buttonSetCaption()' method allows you to change the text displayed on the button itself depending on the current state.
Open your document in Adobe Acrobat DC, go to 'Tools' in the top menu, and select 'Prepare Form'.
Right-click the button you want to use as the toggle switch and select 'Properties' from the context menu.
Navigate to the 'Actions' tab. Select 'Mouse Up' for the Select Trigger dropdown, choose 'Run a JavaScript' for the Select Action dropdown, and click the 'Add...' button.
In the JavaScript Editor, enter your logic. For example: var f = this.getField('TargetFieldName'); if (f.readonly) { f.readonly = false; event.target.buttonSetCaption('Lock Fields'); } else { f.readonly = true; event.target.buttonSetCaption('Unlock Fields'); }
Click 'OK' to save the script, close the Properties dialog, and exit the form editing mode to test your new lock/unlock button.

Edit and Protect PDF Form Fields in WPS Office
While Acrobat scripts offer advanced toggles, WPS PDF provides an intuitive interface to create, manage, and lock PDF form fields directly without needing complex JavaScript coding.
- 1. Open PDF Document: Launch WPS Office and open your interactive PDF form.
- 2. Navigate to the Form Tab: Click on the 'Form' tab located in the top navigation ribbon to access form editing tools.
- 3. Open Field Properties: Double-click on the specific form field you want to protect, or right-click and select 'Properties'.
- 4. Lock the Field Natively: In the Properties dialog, check the 'Read-Only' option under the General tab to instantly lock the field without any scripting.

Frequently Asked Questions
Can I lock multiple PDF form fields at once using a script?
Yes. You can define an array of field names in your JavaScript (e.g., var fields = ['Field1', 'Field2'];) and use a 'for' loop to iterate through them, applying the 'readonly = true' property to each one simultaneously.
Why is my buttonSetCaption script not updating the text?
Ensure that the script is attached to the specific button triggering the event and that the trigger is set to 'Mouse Up'. If the button has states (like Down or Rollover) with hardcoded labels, they might override the JavaScript caption.
Do locked PDF form fields still submit their data when the form is sent?
Yes. Making a field 'readonly' only prevents users from editing the text or selection. Its underlying value remains intact and will still be included when the form data is submitted or exported.
Can I use JavaScript to unlock fields after the PDF is digitally signed?
Typically, applying a digital signature intentionally locks specific fields or the entire document to prevent post-signing tampering. Attempting to unlock these fields via a button script will usually fail or invalidate the signature entirely.




