Make Specific Acrobat Form Sections Read-Only with JavaScript
Question details
Make a button in a fillable PDF set only the fields in its corresponding section to read-only.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A fillable PDF contains multiple sections, each with its own button for locking that section's fields.
- Observed behavior
- Each button should lock its designated fields without making the rest of the form read-only.
Open the PDF in Acrobat and use Prepare a form to check the exact names of the fields in each section. Decide whether each button should only lock fields or also unlock them on a later click.
Add a JavaScript action to each section button
Use a button's Mouse Up action to set only the named fields in its section to read-only.
In Acrobat, open the PDF and select All tools > Prepare a form. Check the field list for the names of the section's fields.
Double-click the section's button, open the Actions tab, and select Mouse Up as the trigger. Choose Run a JavaScript as the action and click Add.
In the JavaScript editor, enter the following script for fields named Text1 through Text10, then click OK: for (var i = 1; i <= 10; i++) { var field = this.getField("Text" + i); if (field) field.readonly = true; }
Open the Actions tab for each remaining section button and add a script using that section's field names and range. For example, change the loop to 11 through 20 if the next section contains Text11 through Text20.
Close the button properties, save the PDF, and exit form editing. Click each button and verify that its fields are read-only while fields in other sections remain editable.

Work with PDF and Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDF and Office files. Its format compatibility helps you move existing documents into WPS; use Acrobat for the button JavaScript described above.

Frequently Asked Questions
How do I find the exact names of my PDF form fields?
In Acrobat, open All tools > Prepare a form and check the field list or open a field's properties. The names in the script must match the form field names.
What if my section's fields are not numbered in sequence?
In the button's Run a JavaScript action, target each field by its exact name, such as this.getField("CustomerName").readonly = true, and repeat for the other fields in that section.
How can I make the fields editable again?
Add a button action that targets the same fields and sets readonly to false, or use a toggle script that switches the section's fields between true and false.
Why does the button work in Acrobat but not another PDF viewer?
PDF viewers differ in their support for form JavaScript. Test the saved form in Acrobat and check whether JavaScript is enabled in the viewer where the button fails.




