PDF Editing Issues

How to Make Fillable PDFs Read-Only and Restore with JavaScript

Steven ParkerSteven Parker Nov 5, 2026 868 views

Question details

The user needs to learn how to dynamically toggle the editable state of a fillable PDF form using JavaScript, specifically making it read-only for a submission event and restoring it afterwards.

How to Make Fillable PDFs Read-Only and Restore with JavaScript
Product
PDF Editor
Device & OS
not provided
Scenario
Managing fillable PDF form states before and after form submission.
Observed behavior
The form needs to be locked (read-only) during the data submission process and unlocked (fillable) dynamically using a JavaScript function.
Before you start

Ensure you are using a PDF editor that supports JavaScript execution and that you are familiar with adding document-level or button-level action scripts.

Solution 1Recommended

Toggle Form Fields to Read-Only or Editable using JavaScript

Use a JavaScript loop to iterate through all form fields in the document and change their boolean readonly status.

In PDF JavaScript, the 'readonly' property is a boolean, meaning it has only two states: true or false. By utilizing a simple 'for' loop, you can quickly change the state of every field in your document at once.

1
Access the JavaScript action properties

Open your PDF form in your PDF editor. Right-click the button or event (like a 'Submit' button) where you want to add the script, select 'Properties', and navigate to the 'Actions' tab. Choose 'Run a JavaScript' as the action.

2
Add the read-only script

To lock the form fields prior to submission, add the following script: for (var i = 0; i < this.numFields; i++) { this.getField(this.getNthFieldName(i)).readonly = true; }

3
Add the restore script

To restore the form to an editable state after submission, use the same loop but change the boolean value to false: for (var i = 0; i < this.numFields; i++) { this.getField(this.getNthFieldName(i)).readonly = false; }

Toggle Form Fields to Read-Only or Editable using JavaScript
Script Timing: Ensure that the script meant to restore the fillable state (readonly = false) runs only after the submission process has fully completed to prevent unintended data modifications during transfer.
Efficient PDF Form Management

Easily Manage and Secure PDF Forms with WPS Office

WPS PDF provides comprehensive tools for creating, editing, and managing fillable forms. You can easily adjust field properties, set up interactive elements, and secure your documents in a user-friendly interface.

  1. 1. Open your PDF: Launch WPS Office and open your fillable PDF document.
  2. 2. Access form tools: Navigate to the 'Form' tab on the top ribbon to view all form creation and editing tools.
  3. 3. Modify properties: Double-click any form field to open its properties, where you can manually set it to 'Read-Only' or adjust other interactive settings.
Easily create and manage interactive fillable PDF forms without advanced coding.Seamlessly compatible with Adobe Acrobat PDF formats and form structures.Robust document security options to lock, encrypt, or restrict form editing.Lightweight alternative with an intuitive and familiar user interface.
microsoft office alternative - wps office

Frequently Asked Questions

What does the readonly property do in a PDF form?

The readonly property is a boolean (true/false) setting that determines whether a user can interact with and change the content of a specific form field. When set to true, the field displays its data but cannot be altered.

Can I lock specific PDF fields instead of the whole document?

Yes. Instead of using a loop that iterates through 'this.numFields', you can target specific fields using 'this.getField("FieldName").readonly = true;' to lock only the fields you choose.

Why use JavaScript instead of standard PDF security passwords?

JavaScript allows for dynamic state changes during specific actions. For example, you can lock fields momentarily during a submission process and unlock them automatically afterward, which static security passwords cannot achieve.