PDF Editing Issues

How to Count Specific Text Values in Acrobat PDF Form Fields

Steven ParkerSteven Parker Nov 3, 2026 869 views

Question details

The user needs to automatically count how many times specific text values (like 'C' or 'D') appear across multiple form fields in a PDF, while ignoring any empty fields.

How to Count Specific Text Values in Acrobat PDF Form Fields
Product
Adobe Acrobat
Device & OS
not provided
Scenario
Creating dynamic PDF forms that require calculating the total occurrences of specific text inputs across numerous sequentially named fields.
Observed behavior
The user needs to set up calculation fields using custom JavaScript to tally specific string values accurately across up to 135 fields.
Before you start

Ensure you have the exact names for all your form fields noted down, as the custom script relies on sequential naming patterns (e.g., cd.1.1, cd.1.2) to loop through and count the values correctly.

Solution 1Recommended

Use a Custom Calculation Script to Loop Through Fields

Use JavaScript within a calculation field's properties to iterate through sequentially named form fields and count occurrences of specific text.

This method requires your target fields to be named in a predictable, numbered sequence so the script can loop through them using a counter variable.

1
Enter Prepare Form Mode

Open your PDF form in Acrobat, navigate to the Tools menu, and select Prepare Form.

2
Access Field Properties

Right-click the specific field where you want the total count for 'C' to appear and select Properties.

3
Add a Custom Calculation Script

Navigate to the Calculate tab, select the 'Custom calculation script' option, and click the Edit button.

4
Enter the Loop Script

Enter the following script, adjusting the prefix 'cd.1.' and the maximum number '135' to match your actual form fields: var total = 0; for (var i = 1; i <= 135; i++) { if (this.getField("cd.1." + i).valueAsString === "C") total++; } event.value = total;

5
Repeat for Additional Values

For the total 'D' field, repeat this entire process on a new calculation field, changing the script comparison from "C" to "D".

Use a Custom Calculation Script to Loop Through Fields
Field Naming Pattern: Your field names must precisely match the concatenated string in the script (e.g., field.1, field.2). Any deviation in the naming convention will cause the script to fail.
Edit PDF Forms with WPS Office

Easily Edit and Manage PDF Forms with WPS Office

WPS PDF provides comprehensive tools to create, edit, and fill out interactive PDF forms. You can effortlessly manage form fields, customize properties, and handle complex daily PDF tasks in a highly compatible environment.

  1. 1. Open Your PDF: Launch WPS Office and open your PDF document containing the forms you need to edit.
  2. 2. Navigate to the Form Tab: Go to the 'Form' tab on the top ribbon to access all form creation and editing tools.
  3. 3. Add Form Fields: Click 'Text Field', 'Check Box', or other form controls to add new interactive fields to your document.
  4. 4. Edit Field Properties: Double-click any added field to access its Properties, where you can customize its appearance, behavior, and formatting.
Create and edit interactive PDF forms easilyHighly compatible with Adobe Acrobat PDF formatsLightweight, fast, and user-friendly interfaceAvailable across Windows, Mac, iOS, and Android
microsoft office alternative - wps office

Frequently Asked Questions

Why is my calculation script not updating the total?

Ensure that your form field names exactly match the naming convention used in your JavaScript loop. Also, check the calculation order in your PDF properties to ensure the total field calculates after the individual input fields are filled.

Does case sensitivity matter in the script?

Yes, JavaScript is case-sensitive. The strict comparison in the script (=== "C") will only count uppercase letters. If you want to count both cases, you must adjust your script to account for lowercase letters as well.

How do I handle empty fields in the calculation?

The provided script specifically checks if the field value exactly matches your target letter. Any empty fields or fields containing other text are automatically ignored during the loop, requiring no extra steps.