Skip to main content
Inspiring
May 10, 2024
Answered

Calculate additional text fields

  • May 10, 2024
  • 3 replies
  • 1298 views

I'm using the following custom calculation script in a text field named 'TotalOTHrs' and it works great. However, I also need to calculate the hours from another 35 dropdowns name 'MBHrs1' to 'MBHrs35.   I'm strugging with how to input that and I could sure use some much appreciated help.  Thanks.

 

var maxFields = 35; //
var total = 0;
for (var i=1; i<=maxFields; i++) {
if (this.getField("OTPayType"+i).valueAsString!="CDO Banked")
total+=Number(this.getField("OTHrs"+i).valueAsString);
}
event.value = total;

This topic has been closed for replies.
Correct answer Nesa Nurani

So if value from dropdown is not "CDO Banked" you want to calculate both "OTHrs" and "MBHrs"?

I ask because in your two posts you used different condition in first you use != "CDO Banked" and in second == "CDO Banked", so which one is it?

If OTHrs and MBHrs are in the same row for each dropdown, you can just sum them, like this:

total+=Number(this.getField("OTHrs"+i).valueAsString)+Number(this.getField("MBHrs"+i).valueAsString);

 

 

 

3 replies

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
May 11, 2024

So if value from dropdown is not "CDO Banked" you want to calculate both "OTHrs" and "MBHrs"?

I ask because in your two posts you used different condition in first you use != "CDO Banked" and in second == "CDO Banked", so which one is it?

If OTHrs and MBHrs are in the same row for each dropdown, you can just sum them, like this:

total+=Number(this.getField("OTHrs"+i).valueAsString)+Number(this.getField("MBHrs"+i).valueAsString);

 

 

 

Inspiring
May 11, 2024

Yes!  That's exactly what I need!  It works great now.  Thank you Nesa!!  You're the best 🙂

Inspiring
May 11, 2024

I definitely need help with the script above so the total hours can calculate from both OTHrs and MBHrs into the text field 'TotalOTHrs', except when the user selects 'CDO Banked' from the OT PayType dropdown.  Please help.

 

Note:  I also have another text field named 'CDOBankedHrs' with the following custom calculation script, which is good.

var total = 0; for (var i=1; i<=35; i++) { if (this.getField("OTPayType"+i).valueAsString=="CDO Banked") total+=Number(this.getField("OTHrs"+i).valueAsString); } event.value = total;

Amal.
Community Manager
Community Manager
May 10, 2024

Hi there

Hope you are doing well and thanks for reaching out.

The workflow you are trying to achieve is might be possible using JavaScript. For more information, please check the help pages listed below:
https://acrobatusers.com/tutorials/javascript_console/
https://helpx.adobe.com/acrobat/using/applying-actions-scripts-pdfs.html

Hope it will help

Regards
Amal