Calculate a Weekly PDF Form Total in Adobe Acrobat While Ignoring Text
Question details
Calculate a weekly total in a PDF form without including day-name labels or other non-numeric field values.

- Product
- Adobe Acrobat PDF forms
- Device & OS
- not provided
- Scenario
- A form has seven daily fields that initially display day names and a Total field that should add numeric entries.
- Observed behavior
- Converting day-name text directly with Number() produces NaN and prevents a valid total.
Open the PDF in an Acrobat version that can edit form fields. In Prepare a form, check the exact names of the seven daily fields and the Total field; the script must use the field names, not just their visible labels.
Add a custom calculation script to the Total field
Use this method to add valid numeric entries while skipping day names, blanks, and other text.
The example assumes the daily fields are named Sun, Mon, Tue, Wed, Thu, Fri, and Sat. Replace those names in the array if your form uses different field names.
In Adobe Acrobat, open the PDF and select All tools > Prepare a form.
Open the Total field's Properties, select the Calculate tab, choose Custom calculation script, and click Edit.
Paste this script into the JavaScript editor: var days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; var total = 0; for (var i = 0; i < days.length; i++) { var text = String(this.getField(days[i]).valueAsString); text = text.replace(/^\s+|\s+$/g, ""); if (text === "" || text === days[i]) continue; var number = Number(text); if (isFinite(number)) total += number; } event.value = isFinite(total) ? total : "";
Click OK to save the script, close the field properties, and save the PDF. Enter numbers in several daily fields while leaving other day names or text in place, then check that Total contains only the numeric sum.

Work with PDFs and Office files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface and Microsoft Office format compatibility for easier migration. It can help you work with PDFs and spreadsheets, but it does not fix or replace an Acrobat JavaScript calculation.

Frequently Asked Questions
Why does the total become NaN when a field contains a day name?
Number("Sun") returns NaN because the day name is not a number. In the Total field's custom calculation script, check for the label before converting the field value.
Where do I add the calculation script in Acrobat?
Open All tools > Prepare a form, open the Total field's Properties, and select Calculate > Custom calculation script > Edit.
What happens if someone enters text other than a day name?
The example script converts each nonblank entry with Number() and adds it only if isFinite() returns true. Other text is ignored.
Do the daily field names have to be Sun through Sat?
No. In Prepare a form, check each field's actual name and update the days array in the script to match. The script uses those names to find the fields.




