PDF Editing Issues

Calculate a Weekly PDF Form Total in Adobe Acrobat While Ignoring Text

Olivia MillerOlivia Miller Nov 19, 2026 869 views

Question details

Calculate a weekly total in a PDF form without including day-name labels or other non-numeric field values.

Calculate a Weekly PDF Form Total in Acrobat While Ignoring Text
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the form editor

In Adobe Acrobat, open the PDF and select All tools > Prepare a form.

2
Edit the Total calculation

Open the Total field's Properties, select the Calculate tab, choose Custom calculation script, and click Edit.

3
Enter the calculation script

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 : "";

4
Save and test the form

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.

Add a custom calculation script to the Total field
Add values, not comparison results: A comparison such as Number(Sun.valueAsString != "Sun") converts true or false to 1 or 0; it does not add the field's numeric value. The script above converts the field value itself after excluding its label.
Free Microsoft Office alternative

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.

Open and work with PDF documents alongside spreadsheetsCompatible with Microsoft Word, Excel, and PowerPoint formatsUse a familiar interface to move between common office tasksGet started with a free, lightweight office suite
microsoft office alternative - wps office

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.