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

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, Macintosh

Views

85

Likes

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

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

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, Macintosh

Views

86

Likes

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
Jun 26, 2019 0
Most Valuable Participant ,
Jun 26, 2019

Copy link to clipboard

Copied

Likes

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
Reply
Loading...
Jun 26, 2019 0
New Here ,
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. 😕

Likes

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
Reply
Loading...
Jun 26, 2019 0
Most Valuable Participant ,
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;

Likes

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
Reply
Loading...
Jun 26, 2019 1
New Here ,
Jun 26, 2019

Copy link to clipboard

Copied

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!

Likes

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
Reply
Loading...
Jun 26, 2019 0