PDF Editing Issues

How to Count Completed Text Fields in a PDF Form

Huma Ashraf ChHuma Ashraf Ch Oct 28, 2026 869 views

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.

How to Count Completed Text Fields in a PDF Form
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.
Before you start

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.

Solution 1Recommended

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.

1
Open Field Properties

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

2
Access Custom Calculation

Navigate to the 'Calculate' tab inside the Properties window. Select the option labeled 'Custom calculation script' and click the 'Edit' button.

3
Write the Counting Script

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++; }

4
Set the Final Value

Add 'event.value = count;' at the end of your script to assign the counted number to the total field, then click 'OK' to save.

Use a Custom JavaScript Calculation Script
Exact Naming: Your script will only work if the field names in the JavaScript array match the actual form field names exactly, including spaces and capitalization.
Edit PDF Forms Seamlessly

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. 1. Open your PDF Document: Launch WPS Office and open your existing PDF document or create a new one.
  2. 2. Access Form Tools: Navigate to the 'Form' tab on the top ribbon to reveal all interactive form controls.
  3. 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. 4. Save and Share: Once your form fields are set up, save the PDF to easily collect data from other users.
Fully compatible with standard PDF form formatsIntuitive interface for adding, editing, and filling text fieldsLightweight software with fast PDF processing and exportingFree built-in tools for merging, splitting, and converting PDFs
microsoft office alternative - wps office

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.