PDF Editing Issues

How to Use a PDF Check Box to Clear and Lock Related Form Fields

Adam DavisAdam Davis Nov 5, 2026 869 views

Question details

The user needs to set up an 'N/A' check box in a PDF form that clears and locks related text fields, check boxes, and calculated fields when selected, and restores them when unchecked.

How to Use a PDF Check Box to Clear and Lock Related Form Fields
Product
PDF Editors with JavaScript Support
Device & OS
not provided
Scenario
Creating an interactive PDF form where checking an 'N/A' (Not Applicable) box disables specific sections to prevent user input while maintaining synchronization across duplicate fields.
Observed behavior
The user requires a programmatic method (script) to change field states to blank or 'Off' and make them read-only, while ensuring the fields return to their default state if the user unchecks the N/A box.
Before you start

Ensure you are using a professional PDF editor that supports adding custom JavaScript to form fields, and make a backup copy of your PDF file before applying new scripts.

Solution 1Recommended

Apply a Custom JavaScript to the Check Box Properties

Use a custom JavaScript action triggered by a 'Mouse Up' event to dynamically control the values and read-only properties of your target form fields.

By applying a condition-based script to your N/A check box, you can command the PDF reader to check whether the box is ticked. If it is, the script will clear the related fields and lock them. You must also include a mechanism to reverse this action if the user changes their mind and unchecks the box.

To ensure duplicate check boxes synchronize correctly, you should use fully qualified field names in your script.

1
Access Check Box Properties

Open your PDF form in editing mode. Right-click the N/A check box you want to use as the trigger and select 'Properties' from the context menu.

2
Add a Mouse Up Action

Navigate to the 'Actions' tab in the Properties dialog. Choose 'Mouse Up' from the Select Trigger dropdown, and select 'Run a JavaScript' from the Select Action dropdown. Click the 'Add' button to open the JavaScript editor.

3
Input the Locking Script

In the editor, enter an if-statement to clear and lock the fields. For example: if (event.target.value != 'Off') { this.getField('TargetField1').value = ''; this.getField('TargetField1').readonly = true; }. Repeat the getField lines for all related text boxes, check boxes, and calculated fields.

4
Add the Restoration Script

Below your if-statement, add an 'else' block to restore the fields when unchecked: else { this.getField('TargetField1').readonly = false; }. This ensures the fields become editable again if the N/A box is deselected.

5
Save and Test

Click 'OK' to save the script, close the Properties dialog, and exit form editing mode. Click the N/A check box to test if the related fields clear and lock as expected.

Apply a Custom JavaScript to the Check Box Properties
Handling Check Box Values: For related check boxes that need to be cleared, set their value to 'Off' (e.g., this.getField('CheckBoxD2').value = 'Off';) rather than an empty string.
Professional PDF Editor

Easily Create Interactive PDF Forms with WPS Office

WPS Office provides a comprehensive PDF editor that allows you to effortlessly design interactive forms, insert check boxes, manage text fields, and customize field properties. Build dynamic, professional PDFs with high format compatibility.

  1. 1. Open Your PDF Document: Launch WPS Office and open the PDF file you wish to turn into an interactive form.
  2. 2. Navigate to the Form Tab: Select the 'Form' tab from the top ribbon to reveal the form editing toolbar.
  3. 3. Insert a Check Box: Click the 'Check Box' tool and draw the box on your document where you want the N/A option to appear.
  4. 4. Edit Field Properties: Double-click the newly created check box to open its properties panel, where you can adjust its appearance, name, and interactive behaviors.
Fully compatible with standard PDF form structures and Adobe AcrobatIntuitive form-building tools for check boxes, text fields, and drop-down listsLightweight, fast-loading application with a user-friendly interface
microsoft office alternative - wps office

Frequently Asked Questions

Why aren't my duplicate check boxes synchronizing in the PDF form?

Duplicate check boxes must have the exact same field name and export values to synchronize automatically. If you are using a script, referencing the fully qualified field name ensures that your script's actions affect all duplicates uniformly.

How do I unlock a PDF form field using JavaScript?

To unlock a field, you must set its readonly property to false. In your check box script, you can add an 'else' condition that triggers when the box is unchecked, containing a line like: this.getField('YourFieldName').readonly = false;

Can I use a Validate script instead of a Mouse Up action?

Yes, a Validate script can also be used. However, a 'Mouse Up' action is generally preferred for check boxes and buttons because it triggers exactly when the user clicks and releases the mouse, providing immediate visual feedback.

How do I clear a calculated field in a PDF without breaking the calculation?

You can clear a calculated field by using JavaScript to set its value to an empty string. However, you must also ensure your original calculation script contains logic to stop calculating (or return empty) if the N/A check box is checked, otherwise the calculation may instantly overwrite your empty string.