How to Count Completed Text Fields in a PDF Form
Question details
The user needs to calculate the total number of text fields in a PDF form that contain text (such as names) rather than numeric values.

- Product
- Adobe Acrobat / PDF Editors
- Device & OS
- not provided
- Scenario
- Setting up a PDF form to track how many participants or names have been entered into specific text fields.
- Observed behavior
- Using the built-in 'Value is the sum of the following fields' function fails to add the fields together because they contain text entries instead of numeric values.
Ensure you have noted the exact field names (e.g., RANKNAMEEXECUTIVE OFFICER) used in your PDF form, as you will need to reference them identically in your script.
Use a Custom JavaScript Calculation Script
Replace the default sum function with a custom JavaScript snippet that checks each field and increments a counter if the text field is not empty.
The built-in sum calculation only evaluates numeric data. To count names or other strings of text, you must use a script to check whether a field contains text and manually increase the total count.
Enter Form Editing mode in your PDF editor. Right-click the total field where you want the final count to be displayed and select 'Properties'.
Navigate to the 'Calculate' tab inside the Properties window. Select the option labeled 'Custom calculation script' and click the 'Edit' button.
Define an array containing your exact field names and use a loop to check their values. For example: var fields = ['RANKNAMEEXECUTIVE OFFICER', 'RANKNAMECOMAND MASTER CHEIF']; var count = 0; for (var i = 0; i < fields.length; i++) { if (this.getField(fields[i]).valueAsString !== '') count++; }
Add 'event.value = count;' at the end of your script to assign the counted number to the total field, then click 'OK' to save.

Easily Create and Manage PDF Forms with WPS Office
WPS Office features a robust PDF editor that allows you to easily create interactive forms, add text fields, and manage document properties without complex workflows.
- 1. Open your PDF Document: Launch WPS Office and open your existing PDF document or create a new one.
- 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to reveal all interactive form controls.
- 3. Add or Modify Fields: Click 'Text Field' to insert new text input areas, or double-click existing fields to adjust their properties and names.
- 4. Save and Share: Once your form fields are set up, save the PDF to easily collect data from other users.

Frequently Asked Questions
Why does the 'Sum' calculation return zero for my text fields?
The standard 'Sum' function in PDF editors strictly calculates numeric values. If your fields contain text such as names or letters, the software ignores them, resulting in a sum of zero.
How do I find the exact name of a form field?
While in form editing mode, double-click the specific field or right-click it and select 'Properties'. The exact name will be listed under the 'General' tab.
Does my calculation script update automatically when a user types?
Yes, PDF form calculation scripts trigger automatically whenever a field value changes or the user clicks outside the text field they just filled.




