How to Make a PDF Form Field Read-Only Based on Another Field's Value
Question details
The user needs to configure a PDF form so that entering a value in one field automatically disables (makes read-only) another field.

- Product
- Adobe Acrobat / PDF Editors
- Device & OS
- not provided
- Scenario
- Creating an interactive accounting or data entry PDF form where two fields (such as debit and credit) are mutually exclusive, preventing users from filling out both.
- Observed behavior
- The user wants the credit field to lock and become read-only dynamically whenever the debit amount entered is greater than zero.
Ensure you are using a PDF editor that supports JavaScript execution for form fields, and note down the exact, case-sensitive names of both the trigger field and the target field.
Apply a Custom JavaScript Validation Script
Use a short JavaScript snippet in the field's properties to dynamically change the read-only status of the target field based on the input value.
PDF forms support JavaScript to create dynamic interactions. By adding a validation script to the first field (e.g., Debit), you can command the PDF viewer to check the inputted number and lock the second field (e.g., Credit) if the condition is met.
Open your PDF document in your PDF editor and enter 'Prepare Form' or 'Form Editing' mode to reveal all form fields.
Right-click the trigger field (for example, the 'Debit' field) and select 'Properties' from the context menu.
In the Properties dialog box, click on the 'Validate' tab, then select the option 'Run custom validation script'.
Click the 'Edit' button and enter the following code: this.getField("Name of other field").readonly = (Number(event.value) > 0); Replace "Name of other field" with the exact name of your target field.
If you need both fields to disable each other, repeat these steps on the second field, swapping the field name in the script to point back to the first field.

Create and Manage Interactive PDF Forms with WPS Office
WPS Office provides an easy-to-use, powerful PDF editor that allows you to seamlessly create, fill, and manage interactive PDF forms without needing expensive software.
- 1. Open Your Document: Launch WPS Office and open your PDF document using the WPS PDF tool.
- 2. Navigate to the Form Tab: Click on the 'Form' tab in the top navigation ribbon to access all interactive form controls.
- 3. Insert Form Fields: Select the desired field type (Text Field, Check Box, etc.) and click on the page to place it.
- 4. Adjust Properties: Double-click the inserted field to modify its name, appearance, and basic interactive properties, then save the document.

Frequently Asked Questions
Why isn't the target field locking when I type a value?
This usually happens for three reasons: the field name in your script doesn't match the actual target field name (remember it's case-sensitive), your PDF viewer has JavaScript disabled in its security settings, or you haven't tabbed out of the trigger field to commit the value.
Can I make multiple PDF form fields read-only at the same time?
Yes. You can expand your custom validation script by adding additional lines for each field. For example: this.getField("Field2").readonly = (Number(event.value) > 0); this.getField("Field3").readonly = (Number(event.value) > 0);
Will this JavaScript validation work on mobile PDF readers?
JavaScript support varies significantly across mobile PDF apps. While the script will work perfectly on desktop software like Adobe Acrobat or WPS Office, mobile users might not experience the dynamic locking effect if their app does not support advanced PDF JavaScript.




