PDF Editing Issues

How to Lock and Unlock PDF Form Fields Using One Button

John WilsonJohn Wilson Nov 3, 2026 869 views

Question details

The user needs a method to toggle PDF form fields between editable and read-only states using a single form control.

How to Lock and Unlock PDF Form Fields Using One Button
Product
PDF Editor
Device & OS
not provided
Scenario
Creating interactive PDF forms where certain text fields need to be locked or unlocked dynamically by the user.
Observed behavior
Requires a script or action to manage the read-only property of target PDF fields from a single button or checkbox.
Before you start

Ensure you are using a PDF editing software that supports form field creation and custom JavaScript execution, such as Adobe Acrobat or WPS Office PDF.

Solution 1Recommended

Toggle Read-Only Status Using a JavaScript Button Action

Assign a MouseUp JavaScript action to a button or checkbox to switch the read-only property of specific form fields on or off.

Interactive PDF forms rely on JavaScript to manipulate field properties dynamically. By accessing the 'readOnly' property of a field, you can easily switch its state using a basic logic inversion (!f.readOnly) or an if/else conditional statement tied to a button.

1
Add a Button or Checkbox to Your PDF

Open your PDF document in form editing mode. Navigate to the form controls menu and insert a 'Button' or 'Checkbox' onto the page.

2
Access the Action Properties

Right-click the newly created button or checkbox and select 'Properties'. Go to the 'Actions' tab to configure its behavior.

3
Configure the JavaScript Trigger

Set the 'Select Trigger' option to 'Mouse Up'. Next, set the 'Select Action' dropdown to 'Run a JavaScript', and click the 'Add' button to open the script editor.

4
Enter the Toggle Script

To toggle a single specific field directly, enter the following script: var f = this.getField('myTextField'); f.readOnly = !f.readOnly;

5
Use Conditional Logic for Checkboxes (Optional)

If you are using a checkbox, you can explicitly check its state to lock or unlock the field: if (event.target.value == 'Off') { this.getField('SomeField').readOnly = false; } else { this.getField('SomeField').readOnly = true; }

Toggle Read-Only Status Using a JavaScript Button Action
Test Your Form: After saving the script, exit form editing mode and click the button to verify that your target text field successfully toggles between locked and editable states.
Manage Interactive PDF Forms

Edit and Fill PDF Forms Seamlessly with WPS Office

WPS Office provides a robust PDF editor that allows you to manage, fill, and interact with dynamic PDF forms with ease, ensuring high compatibility with standard PDF formats.

  1. 1. Download and Install WPS Office: Get the free WPS Office suite from the official website and install it on your device.
  2. 2. Open Your PDF Form: Launch WPS PDF and open the document containing your interactive form fields.
  3. 3. Fill and Interact: Click directly into the form fields to input data, or click interactive buttons to trigger dynamic actions.
  4. 4. Save and Export: Once the form is filled out, easily save your changes or export the document for secure sharing.
Easily fill interactive PDF forms with text fields, checkboxes, and buttons.Fully compatible with Adobe PDF formats and interactive elements.Lightweight and fast, offering a smooth reading and editing experience.Convert PDFs to Word, Excel, or PowerPoint with high accuracy.
microsoft office alternative - wps office

Frequently Asked Questions

Can I lock all fields in a PDF at once using JavaScript?

Yes, you can write a JavaScript loop that iterates through all fields in the document and sets their readOnly property to true. Alternatively, you can use the 'Flatten' feature in your PDF editor to permanently merge the fields with the document.

Why isn't my JavaScript executing when I click the button?

Ensure that JavaScript is enabled in your PDF viewer's preference settings. Some applications and browsers disable JavaScript execution in PDFs by default due to security reasons.

Does the toggle script work on mobile PDF readers?

Support varies significantly across mobile devices. While standard desktop applications like Adobe Acrobat or WPS PDF will run the scripts, many built-in mobile PDF viewers do not support JavaScript actions. Always test interactive forms on your intended target devices.