How to Clear Specific PDF Form Fields Using Acrobat JavaScript
Question details
The user wants to create a form button that automatically searches every field and clears the contents of any text field containing a specific word, such as "General."

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Developing or modifying an interactive PDF form where specific default text needs to be bulk-cleared without affecting other filled data.
- Observed behavior
- The user needs a programmatic way to selectively erase values matching a specific string across multiple text fields instead of manually deleting them one by one.
Ensure your PDF document contains interactive form fields and that you are using a PDF editor capable of adding custom JavaScript to form buttons.
Use a Button Action with Custom JavaScript
Attach a custom JavaScript loop to a button field to iterate through all document fields, identify text fields, and clear them if they contain the target word.
Adobe Acrobat allows you to attach custom JavaScript routines to interactive form elements. By adding a script to a 'Clear' button, you can evaluate the contents of every field and selectively erase values based on regular expressions.
Open your PDF file in Adobe Acrobat and select 'Prepare Form' from the Tools menu.
Click the 'Add a Button' icon in the top toolbar and place the button on your document. Double-click the button to open its Properties dialog.
Navigate to the 'Actions' tab within the Properties dialog. Set 'Select Trigger' to 'Mouse Up'.
From the 'Select Action' dropdown, choose 'Run a JavaScript' and click the 'Add' button to open the JavaScript Editor.
Paste the following script into the editor: for (var i = 0; i < this.numFields; i++) { var f = this.getField(this.getNthFieldName(i)); if (f && f.type == "text" && /General/.test(f.valueAsString)) { f.value = ""; } }
Click 'OK' to save the script, close the Properties dialog, and click 'Preview' at the top right to test the button's functionality.
Edit and Manage PDF Forms Easily with WPS Office
While advanced JavaScript configuration is specific to Adobe Acrobat, WPS Office provides a comprehensive, lightweight, and free alternative for managing standard PDF documents. You can effortlessly view, edit, and fill PDF forms alongside seamless handling of all your standard office files.
- 1. Download and Install: Visit the official WPS Office website to download the free suite and install it on your device.
- 2. Open Your Files: Launch WPS Office and open your PDF documents or Microsoft Office files directly within the unified workspace.
- 3. Manage Forms Seamlessly: Navigate to the PDF toolkit to easily fill out forms, add text, or convert documents without needing complex scripts.

Frequently Asked Questions
Can I use this JavaScript to clear all fields regardless of their content?
Yes. To clear all fields entirely, you can either remove the specific text condition in the JavaScript logic, or simply use the built-in 'Reset Form' action available in the button properties instead of writing a custom script.
Does this script work on drop-down menus or checkbox fields?
The provided script specifically checks for text fields using the condition 'f.type == "text"'. If you want it to apply to combo boxes or other field types, you will need to modify or expand the type condition in the script.
Why isn't my JavaScript button working when viewed in a web browser?
Most built-in web browser PDF viewers (like Chrome or Edge) do not fully support Adobe Acrobat JavaScript. The script will only execute reliably when the document is opened in dedicated PDF applications like Adobe Acrobat or Adobe Reader.
Is JavaScript the only way to clear specific form fields?
If you only want to clear specific fields without checking their specific text contents, you can use the built-in 'Reset a form' action in the button properties and manually select which specific fields should be cleared when the button is clicked.




