Calculate Weekly Hours or Enter a Manual Total in an Acrobat PDF Form
Question details
Create a PDF form that calculates weekly hours from daily entries or accepts a validated manual total.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A user fills in daily hours or, when no daily hours are entered, supplies a weekly total.
- Observed behavior
- The Total field should become read-only when a valid daily value is present and editable when all daily fields are blank or contain placeholder labels.
Open the PDF in Acrobat and use Prepare a form to create text fields named Mon, Tue, Wed, Thu, Fri, Sat, Sun, and Total. Enable Acrobat JavaScript and ensure field calculations are enabled in Acrobat preferences.
Use Acrobat field scripts to calculate or enter weekly hours
Use separate validation and calculation scripts to switch the Total field between automatic and manual entry.
A daily value of 0 counts as an entered value and triggers automatic calculation. Calculated totals are not restricted to the manual-entry range of 1 to 37.5.
The scripts treat blank daily fields and matching day labels as empty. Prefer separate visible labels over placeholder values: a field's default value is real form data, not a native placeholder.
In Prepare a form, open Properties for each daily field. On the Validate tab, select Run custom validation script and enter the following script for each field: var s = String(event.value).replace(/^\s+|\s+$/g, ''); var label = event.target.name; if (s !== '' && s.toLowerCase() !== label.toLowerCase()) { if (!/^(?:\d+\.?\d*|\.\d+)$/.test(s) || Number(s) < 0 || Number(s) > 12) { app.alert('Enter a number from 0 to 12, or leave the field blank.'); event.rc = false; } }
Open Total Properties, leave Read Only unchecked on the General tab, and choose Calculate > Custom calculation script. Enter: var names = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']; var sum = 0; var hasDaily = false; for (var i = 0; i < names.length; i++) { var s = String(this.getField(names[i]).valueAsString).replace(/^\s+|\s+$/g, ''); if (s === '' || s.toLowerCase() === names[i].toLowerCase()) continue; if (/^(?:\d+\.?\d*|\.\d+)$/.test(s) && Number(s) >= 0 && Number(s) <= 12) { sum += Number(s); hasDaily = true; } } var wasReadOnly = event.target.readonly; event.target.readonly = hasDaily; if (hasDaily) { event.value = sum; } else if (wasReadOnly) { event.value = ''; }
In Total Properties, choose Validate > Run custom validation script and enter: if (!event.target.readonly) { var s = String(event.value).replace(/^\s+|\s+$/g, ''); if (s !== '' && (!/^(?:\d+\.?\d*|\.\d+)$/.test(s) || Number(s) < 1 || Number(s) > 37.5)) { app.alert('Enter a total from 1 to 37.5, or leave the field blank.'); event.rc = false; } } This permits a blank Total while the form is being completed; add a separate submission check if a total must be required.
Close Prepare a form and enter a value in Mon. Confirm that Total shows the sum and cannot be edited. Clear all daily values and confirm that Total becomes editable; then test manual values inside and outside 1 to 37.5.

Review and Edit PDF Documents with WPS Office
WPS Office is a free, lightweight alternative for working with PDF documents and familiar Office files. Its interface and format compatibility make it easy to move everyday document work between office suites. Use Acrobat to create and test the JavaScript form described above.

Frequently Asked Questions
Does entering 0 in a daily field make Total read-only?
Yes. Zero is a valid daily value from 0 to 12, so the calculation script includes it and makes Total read-only.
What happens when I clear the last daily entry?
The calculation script makes Total editable and clears the previous calculated total. You can then enter a manual value from 1 to 37.5.
Can the calculated total exceed 37.5 hours?
Yes. The 1 to 37.5 validation applies only to manual Total entries. Each daily entry is limited to 0 through 12.
Why shouldn't I rely on default values as placeholders?
A default value is stored as field data and can be submitted or used in calculations. Use separate day labels where possible; if you use default values, ensure the scripts recognize them.
Will the form scripts work in every PDF viewer?
Not necessarily. PDF viewers differ in their support for Acrobat JavaScript and field calculations. Test both entry modes in the viewer your recipients will use.




