How to Count Text Fields in a PDF Form with a Custom Script
Question details
The user needs to dynamically count the number of form fields containing text within a PDF, replicating the behavior of the COUNTA function found in spreadsheet software.

- Product
- Adobe Acrobat XI
- Device & OS
- not provided
- Scenario
- Setting up a PDF form calculation to tally and display the total number of non-empty text entries.
- Observed behavior
- The user is unable to find built-in tools like 'Table' or 'Add Summary Row' buttons in Acrobat XI and requires a scripted solution to count the fields.
Ensure you know the exact names of the text fields you wish to count, as you will need to reference them accurately within your JavaScript array.
Use a Custom JavaScript Calculation
You can achieve the COUNTA functionality by applying a custom calculation script to a target summary text field. This script iterates through specified fields and tallies the non-empty ones.
Because standard summary functions in PDF software often focus on mathematical sums rather than counting non-empty fields, a simple JavaScript loop provides full control over determining which fields should be counted.
Launch your PDF editor (such as Adobe Acrobat) and open your PDF document. Activate the form editing mode, typically found under 'Prepare Form', to view all form fields.
Add a new text field in the location where you want the total count to appear. Right-click this new field and select 'Properties'.
Navigate to the 'Calculate' tab within the Properties window. Select the 'Custom calculation script' radio button and click the 'Edit' button.
Paste the following script into the JavaScript editor: var fieldNames = ["Field1", "Field2", "Field3"]; var total = 0; for (var i in fieldNames) { var f = this.getField(fieldNames[i]); if (f.valueAsString !== "") total++; } event.value = total; Replace 'Field1', 'Field2', and 'Field3' with the exact names of the text fields you wish to count, and click 'OK'.

Manage and Fill PDF Forms with WPS Office
If you need a reliable and fast tool to handle interactive PDF forms, WPS Office provides excellent built-in PDF capabilities. You can seamlessly view, fill out, and manage PDFs without needing heavy, expensive external software.
- 1. Download and Install: Get the free version of WPS Office from the official website and install it on your device.
- 2. Open Your PDF: Launch the WPS Office application, go to the PDF tab, click on 'Open', and select your interactive PDF form.
- 3. Fill and Save: Click directly on the interactive form fields to enter your data, then save or export the completed PDF.

Frequently Asked Questions
Will this custom calculation script work on mobile PDF readers?
Most mobile PDF readers have limited or no support for executing JavaScript calculations. This custom script is primarily designed for desktop PDF applications like Adobe Acrobat or dedicated advanced PDF editors.
How do I find the correct field names to put into the script?
While in your PDF's form editing mode, double-click a field to open its Properties dialog box. The 'Name' input field at the top of the General tab displays the exact identifier you need to place inside the script's array.
Can I use this script to count dropdown selections instead of text fields?
Yes. However, you must ensure that your 'empty' dropdown state returns an empty string. If the default unselected state relies on a placeholder phrase like 'Select an option', you must modify the condition in the script to check against that phrase, such as: if (f.valueAsString !== 'Select an option').




