• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

how to add multiple fields and then divide

New Here ,
Jun 25, 2018 Jun 25, 2018

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.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2018 Jun 26, 2018

Copy link to clipboard

Copied

You can use JavaScript for this.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2018 Jun 26, 2018

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 26, 2018 Jun 26, 2018

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

Screenshot (13).png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2018 Jun 26, 2018

Copy link to clipboard

Copied

What happens when the fields are empty?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 26, 2018 Jun 26, 2018

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2018 Jun 26, 2018

Copy link to clipboard

Copied

The code you posted above should prevent that from happening. I tested it and it works fine for me...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 26, 2018 Jun 26, 2018

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 26, 2018 Jun 26, 2018

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines