PDF Editing Issues

How to Clear Specific PDF Form Fields Using Acrobat JavaScript

Anum MushtaqAnum Mushtaq Nov 5, 2026 869 views

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."

How to Clear Specific PDF Form Fields Using Acrobat JavaScript
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.
Before you start

Ensure your PDF document contains interactive form fields and that you are using a PDF editor capable of adding custom JavaScript to form buttons.

Solution 1Recommended

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.

1
Enter Prepare Form Mode

Open your PDF file in Adobe Acrobat and select 'Prepare Form' from the Tools menu.

2
Add a Button Field

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.

3
Set the Action Trigger

Navigate to the 'Actions' tab within the Properties dialog. Set 'Select Trigger' to 'Mouse Up'.

4
Add the JavaScript

From the 'Select Action' dropdown, choose 'Run a JavaScript' and click the 'Add' button to open the JavaScript Editor.

5
Input the Code

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 = ""; } }

6
Save and Test

Click 'OK' to save the script, close the Properties dialog, and click 'Preview' at the top right to test the button's functionality.

Customizing the Target Word: The /General/ syntax used in the script is a regular expression. You can replace 'General' with any specific text you wish to clear, such as /Draft/ or /Sample/.
Free Microsoft Office alternative

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. 1. Download and Install: Visit the official WPS Office website to download the free suite and install it on your device.
  2. 2. Open Your Files: Launch WPS Office and open your PDF documents or Microsoft Office files directly within the unified workspace.
  3. 3. Manage Forms Seamlessly: Navigate to the PDF toolkit to easily fill out forms, add text, or convert documents without needing complex scripts.
Fully compatible with Microsoft Office formats (.docx, .xlsx, .pptx) and standard PDF files.Built-in PDF toolkit to effortlessly view, fill, edit, and manage standard PDF form data.Lightweight installation with a user-friendly, familiar interface.Free to download and use for your daily document management needs.
microsoft office alternative - wps office

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.