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

JavaScript - Want to calculate sum of certain fields, but only if dropdown next to each field has a particular value showing. Graphic included.

New Here ,
Jun 26, 2019 Jun 26, 2019

Copy link to clipboard

Copied

Here's the English version of what I'm trying (and failing) to do:

The plain English version of the calculation I’m trying to make for each of the “Total” fields.

Allow value from “c1_w_1”, IF field “camp_1” = “Dougy”

+

Allow value from “c1_w_2”, IF field “camp_2” = “Dougy”

+

Allow value from “c1_w_3”, IF field “camp_3” = “Dougy”

and so on...

It feels as though it needs to be a doc sript and not a field properties script. Below is a graphic to illustrate the functionality I'm trying to recreate in this PDF form.

Goal.jpg

Any feedback would be greatly appreciated!!!

TOPICS
Acrobat SDK and JavaScript

Views

261

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, 2019 Jun 26, 2019

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, 2019 Jun 26, 2019

Copy link to clipboard

Copied

Thank you for sending those lnks. I read through them and was able to understand what they explain, for the most part) but I'm still running into a brick wall on getting this to work. 😕

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, 2019 Jun 26, 2019

Copy link to clipboard

Copied

You can use this code as the custom calculation script of your field:

var total = 0;

if (this.getField("camp_1").valueAsString=="Dougy") total+=Number(this.getField("c1_w_1").valueAsString);

if (this.getField("camp_2").valueAsString=="Dougy") total+=Number(this.getField("c1_w_2").valueAsString);

if (this.getField("camp_3").valueAsString=="Dougy") total+=Number(this.getField("c1_w_3").valueAsString); // etc.

event.value = total;

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, 2019 Jun 26, 2019

Copy link to clipboard

Copied

LATEST

That did it! You're a genious - I had been seeing mention of valueAsString, but did not think it would be the way for me to go at all!!! Thank you so much!

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