PDF Editing Issues

How to Re-Enable PDF Form Fields When a Checkbox Is Cleared

Aamir Naveed AkramAamir Naveed Akram Oct 19, 2026 869 views

Question details

The user needs to use JavaScript in a PDF form to automatically restore disabled text fields to an editable state when a previously selected checkbox is cleared.

How to Re-Enable PDF Form Fields When a Checkbox Is Cleared
Product
PDF Form Editor
Device & OS
not provided
Scenario
Creating an interactive PDF form where two text fields are dynamically controlled by checkboxes. Checking a box disables and clears the opposite field, but unchecking it needs to restore both fields to an editable state.
Observed behavior
Without explicitly handling the unchecked state in the script, the text fields remain read-only or disabled even after the user clears the checkbox selection.
Before you start

Verify the exact names of your text fields and checkboxes in the PDF form properties, as JavaScript requires precise object names to properly target and modify field states.

Solution 1Recommended

Add JavaScript Logic to the Checkbox Mouse Up Action

Apply a custom script to evaluate the checkbox state and explicitly toggle the text fields' read-only properties based on whether the checkbox is checked or cleared.

When dealing with interactive PDF checkboxes, there are three potential states if you have two boxes: box 1 selected, box 2 selected, or neither selected. Your script must account for all these conditions, particularly the "Off" state when a box is cleared.

1
Open Checkbox Properties

Enter form editing mode in your PDF editor, right-click the checkbox you want to configure, and select 'Properties' from the context menu.

2
Set the Action Trigger

Navigate to the 'Actions' tab. Select 'Mouse Up' from the Select Trigger dropdown menu, and choose 'Run a JavaScript' from the Select Action dropdown, then click 'Add'.

3
Write the Unchecked State Logic

In the JavaScript editor, add an 'if' statement to check if the checkbox value is 'Off'. Inside this condition, explicitly set the 'readonly' property of your target text field objects to 'false' so they become editable again.

4
Handle the Checked State

Add an 'else' block for when the checkbox has a positive value (is checked). In this block, set the opposite text field's 'readonly' property to 'true' and set its value to an empty string to clear any existing text.

5
Verify Object Existence

Wrap your property changes in an 'if (oFld)' statement where 'oFld' is your text field object. This ensures the script only attempts to modify the field if the object actually exists, preventing runtime errors.

Add JavaScript Logic to the Checkbox Mouse Up Action
Trigger Selection: Always run field logic from the 'Mouse Up' or 'Validate' action rather than 'Mouse Down', as this ensures the checkbox's value has fully updated before your script evaluates it.
Edit Interactive PDFs with WPS Office

Manage Interactive PDF Forms with WPS PDF

WPS Office offers a robust PDF editor that allows you to easily view, fill out, and manage interactive PDF forms without dealing with complex code.

  1. 1. Open Your PDF: Launch WPS Office and open your interactive PDF document containing the form fields.
  2. 2. Navigate to Form Tools: Go to the 'Form' tab on the top ribbon to access interactive form filling and highlighting tools.
  3. 3. Interact with Checkboxes: Click directly on the checkboxes and text fields; WPS PDF seamlessly processes built-in form logic so you can complete your document efficiently.
Fully compatible with standard PDF forms and Adobe Acrobat interactive fieldsEasily fill checkboxes, radio buttons, and text fields with a user-friendly interfaceLightweight, fast, and packed with free PDF reading and annotation tools
microsoft office alternative - wps office

Frequently Asked Questions

Why doesn't my text field become editable after unchecking the box?

This happens because the script lacks explicit logic for the unchecked state. You must explicitly set the text field's 'readonly' property back to 'false' when the checkbox value evaluates to 'Off'.

What does the 'if (oFld)' statement do in the PDF JavaScript?

It tests whether the form field object (assigned to the variable oFld) actually exists in the document before the script tries to access or modify its properties. This prevents the script from crashing if the field name is incorrect.

Can I hide a text field instead of making it read-only?

Yes. Instead of changing the 'readonly' property, you can modify the 'display' property. Set it to 'display.hidden' when the checkbox is checked, and 'display.visible' when the checkbox is cleared.

Which trigger is most reliable for checkbox JavaScript?

The 'Mouse Up' action is highly recommended for checkboxes. It triggers reliably after the user clicks and releases the mouse, guaranteeing that the script runs against the newly updated checkbox state.