Skip to main content
Participant
Nov 18, 2026 6:59 PM UTC
Question

Timesheet PDF form: how to split weekly hours into regular and overtime when the limit is not always 40?

I'm building a weekly timesheet as a fillable PDF form in Acrobat. Each day has an "hours" field (Mon to Sun), and I want the form to calculate regular hours, overtime hours and total pay automatically.

What I have so far:

Total hours (calculated as the sum of the 7 daily fields):
event.value = Number(this.getField("Mon").value) + Number(this.getField("Tue").value) + Number(this.getField("Wed").value) + Number(this.getField("Thu").value) + Number(this.getField("Fri").value) + Number(this.getField("Sat").value) + Number(this.getField("Sun").value);

Regular hours:
var t = Number(this.getField("TotalHours").value) || 0;
var limit = Number(this.getField("WeeklyLimit").value) || 40;
event.value = Math.min(t, limit);

Overtime hours:
var t = Number(this.getField("TotalHours").value) || 0;
var limit = Number(this.getField("WeeklyLimit").value) || 40;
event.value = Math.max(0, t - limit);

Total pay:
var rate = Number(this.getField("Rate").value) || 0;
var reg = Number(this.getField("RegHours").value) || 0;
var ot = Number(this.getField("OTHours").value) || 0;
event.value = reg * rate + ot * rate * 1.5;

A few questions:
1. Is there a cleaner way to sum the daily fields than adding them one by one, for example with a shared field name prefix like Hours.Mon, Hours.Tue?
2. What is the right way to set the calculation order so TotalHours always updates before RegHours and OTHours?
3. How do I stop the fields from showing 0 or NaN when the form is empty, and round the pay to 2 decimals?

To double check the pay side, I've been comparing the results with an online overtime pay calculator, for example 46 hours at $18 should come out to $882. Is there a better way to test a form like this?

    1 reply

    Karl Heinz  Kremer
    Community Expert
    Community Expert
    Nov 18, 2026 8:48 PM UTC

    Let’s assume you have Hours.Mon, Hours, Tue, and so on, you can do something like this:

     

    var fields = this.getField("Hours");

    var a = fields.getArray();

    var sum = 0;
    for (var i=0; i<a.length; i++) {
    sum += a[i].value;
    }

    this.getField("TotalHours").value = sum;

     

    Translate