How to Make a PDF Form Field Read-Only Conditionally
Question details
The user needs to configure a PDF form field so that it automatically becomes read-only once it is populated with a value, or when another control like a checkbox is selected.

- Product
- PDF Editor
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where specific data fields must be locked from further editing once the user inputs their initial response or triggers a confirmation checkbox.
- Observed behavior
- The goal is to apply logic to form fields so they change state to read-only dynamically based on user interaction.
Ensure you are using an advanced PDF editor that supports form creation and executing custom JavaScript calculations or validations, as basic PDF viewers cannot process these scripts.
Use Custom JavaScript Validation on the Text Field
Apply a short JavaScript snippet to the target text field's properties so it locks itself as soon as the user enters text and clicks away.
This method utilizes the built-in validation triggers of interactive PDF forms. When the user finishes typing and exits the field, the script evaluates if the field is empty. If it contains data, it instantly converts the field properties to read-only.
Launch your PDF editor, open your document, and enter the Form Editing or Prepare Form mode.
Right-click the specific text field you want to lock and select 'Properties' from the context menu.
In the Properties dialog box, click on the 'Validate' tab to manage validation rules for the field.
Select the option to 'Run custom validation script' and enter the following code: this.getField("Your Field Name").readonly = (event.value != "");
Replace 'Your Field Name' within the script with the exact name of your text field. Close the properties window, exit form editing mode, and test the form.

Lock a Text Field Based on a Checkbox Selection
Attach an action script to a checkbox so that checking the box automatically locks a separate text field.
Create and Manage Interactive PDF Forms with WPS Office
WPS Office provides robust PDF editing capabilities, enabling you to effortlessly handle interactive forms, customize text fields, and secure document content without needing heavy or expensive software.
- 1. Install WPS Office: Download and install the free version of WPS Office from the official website.
- 2. Open Your PDF: Launch WPS PDF and open the interactive form you need to manage.
- 3. Access Form Tools: Navigate to the 'Form' tab to access interactive fields, text boxes, and checkbox tools.
- 4. Edit and Save: Modify the form properties as needed, fill in your data securely, and save your finished PDF.

Frequently Asked Questions
Why isn't my PDF field becoming read-only after I type in it?
This usually occurs if the custom JavaScript contains a syntax error or if the field name referenced in the script does not exactly match the actual field name. Double-check your spelling and capitalization.
Can I unlock the field after it becomes read-only?
Once a field is set to read-only via a validation script, standard users cannot edit it again unless you provide a separate 'Reset Form' button or script an explicit action to reverse the read-only status.
Does this JavaScript work on mobile PDF readers?
Most mobile PDF viewer apps do not support custom JavaScript execution. This read-only behavior is best suited for desktop users utilizing fully featured PDF software.




