How to Reset a Text Field When Checking a Checkbox in PDF Forms
Question details
The user needs to reset a text field to its default value automatically whenever a specific checkbox is toggled to make the text field visible.

- Product
- Adobe Acrobat / PDF Form
- Device & OS
- not provided
- Scenario
- Setting up interactive PDF form fields where toggling a checkbox controls a text field's visibility and triggers a reset of its content.
- Observed behavior
- A checkbox successfully shows or hides a text field, but the text field retains old inputted data instead of clearing/resetting when it becomes visible again.
Ensure your PDF editor supports JavaScript for interactive form properties. It is highly recommended to back up your original PDF file before adding custom scripts to prevent accidental data loss.
Use JavaScript in Checkbox Actions to Reset Fields
Add a custom JavaScript snippet to the checkbox properties to clear the target text field whenever the visibility condition is met.
By attaching an action script to the checkbox, you can command the document to reset specific text fields automatically based on the visibility condition. This ensures that hidden fields don't accidentally hold irrelevant data.
Open your PDF document in your form editor (such as Adobe Acrobat) and enter 'Prepare Form' or 'Edit Form' mode.
Right-click the specific checkbox that controls the visibility of your text field and select 'Properties' from the context menu.
Navigate to the 'Actions' tab. Select 'Mouse Up' as the trigger, choose 'Run a JavaScript' from the 'Select Action' dropdown, and click the 'Add' button.
In the JavaScript editor window, enter a condition to check visibility, followed by the reset command. For example: `if (nHide == display.visible) { this.resetForm(["YourTextFieldName"]); }`. Replace 'YourTextFieldName' with the exact name of your text field.
Click 'OK' to save the script, then close the properties window. Exit the form editing mode and toggle the checkbox to ensure the text field resets properly upon becoming visible.

Easily Create and Manage Interactive PDF Forms with WPS Office
WPS Office includes a robust, built-in PDF editor that allows you to view, fill, and create interactive forms effortlessly. It natively supports comprehensive form field properties and actions.
- 1. Download and install: Download WPS Office for free from the official website and install it on your device.
- 2. Open your PDF: Launch WPS Office, go to the PDF tab, and open your existing PDF document or create a blank one.
- 3. Use form tools: Navigate to the 'Form' tab on the top ribbon to insert Text Fields, Checkboxes, and Dropdowns.
- 4. Customize properties: Double-click any inserted form field to edit its properties, format, and interactions to build your interactive document.

Frequently Asked Questions
Can I reset multiple fields with one checkbox action?
Yes. In the JavaScript `this.resetForm([])` array, you can list multiple exact field names separated by commas. For example: `this.resetForm(["TextField1", "TextField2"]);`.
Why doesn't the text field clear when I uncheck the box?
The script triggers the reset based on your `if` condition (e.g., checking if the field is set to visible). To clear it when the checkbox is unchecked or hidden, you need to adjust your JavaScript logic to execute when the condition equals hidden or off.
How do I find the exact name of my text field?
In your PDF form editing mode, the field names are usually displayed directly over the fields as labels. You can also right-click the field and check its 'Properties' under the General tab to find, copy, or rename the exact field name.
Will this JavaScript work in all PDF readers?
Standard JavaScript form commands like `resetForm` are supported in most dedicated PDF readers (including Adobe Acrobat and WPS Office) but might be restricted or ignored in simplified web-browser PDF viewers.




