Copy link to clipboard
Copied
I need to add together two columns "Actual Hours" and "Actual Pets", then divide to get "Hours/Pet". I then need a running total for each day of the week that provides the week to date and the month to date.
My goal is this: (AHMonday + AHTuesday + AHWednesday + AHThursday + AHFriday) / (APMonday + APTuesday + APWednesday + APThursday + APFriday)
The average is not the same as week to date (off slightly, but very important this be accurate) and I need to account for fields being empty without sending errors for not completing the calculations. I am using adobe acrobat pro.
Copy link to clipboard
Copied
You can use JavaScript for this.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Sorry, I intend to use javascript and have looked over that link but I am still not able to write the javascript I need. Its the week to date and month to date I am struggling with. The simple calculation worked great until I ran into the errors for having the document not filled in yet. This is what I have for "Para/Pet" for Monday:
var numerator = +getField("AHMonday").value;
var denominator = +getField("APMonday").value;
event.value = denominator !== 0 ? numerator / denominator : "";
Copy link to clipboard
Copied
What happens when the fields are empty?
Copy link to clipboard
Copied
"The value entered does not match the format of the field". This happens when there is a field blank. The form would be filled out during the month and build up so keeping blank fields out of the calculations is pretty important.
Copy link to clipboard
Copied
The code you posted above should prevent that from happening. I tested it and it works fine for me...
Copy link to clipboard
Copied
The code I posted works perfectly to calculate "Para/Pet" but how do I enter the week to date and month to date?
Copy link to clipboard
Copied
You mean the formula in your original post? You need to use the same logic.
Create a variable that holds the numerator value and one that holds the denominator, and only apply the calculation if the latter is not zero.