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

Script for counting both Yes and No's in a column and returning the # of Yes's out of the Total

Explorer ,
Jun 29, 2016 Jun 29, 2016

(Acrobat Pro)

I have 5 fields (DRDropdown1-5) in which have 3 options (Y, N, NA). I only
want to count the number of Y's and N's and then return the # of Y's out of the
total Y's+N's.

Any assistance is appreciated. I figure if I see enough code, that I'll pick
it up.

Thanks

TOPICS
Acrobat SDK and JavaScript , Windows
671
Translate
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

correct answers 1 Correct answer

Community Expert , Jun 29, 2016 Jun 29, 2016

We don't usually present complete solutions, given a description or an example of how to do the hard part, you should be able to take your JavaScript knowledge and add the missing pieces. If you are not that familiar with JavaScript, do yourself a favor and look at some introductory material (I like this for JavaScript in Acrobat: Beginning JavaScript for Adobe Acrobat ).

Looking at your script, you already have most of the functionality in place. You should be able to change the output (assuming

...
Translate
Community Expert ,
Jun 29, 2016 Jun 29, 2016

Take a look at this blog post I did a while ago, which explains how to do that: How to Count Radio Button Choices in Acrobat JavaScript - KHKonsulting LLC

Translate
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
Explorer ,
Jun 29, 2016 Jun 29, 2016

Thank you Karl,


Unfortunately, that doesn't work.

1) it only accounts for Y; I need Y & N total

2) I have 20 fields with the same name with 1-20 tacted on. But I only need 1-5, then 6-10, etc. So your group function doesn't work effectively

3) the final output is a single #. I need '# of #'; as in '3 of 4'.

This is the script that I used to produce a %. Can this be modified to produce '# of #'?

var totalY = 0; 

var total = 0; 

for (var i=1; i<=5; i++) { 

    var f = this.getField("CRDropdown"+i); 

    if (f.valueAsString=="Y") { 

        totalY++; 

        total++; 

    } else if (f.valueAsString=="N") { 

        total++; 

    } 

if (total==0) event.value = ""; 

else event.value = totalY / total;

Translate
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 29, 2016 Jun 29, 2016

We don't usually present complete solutions, given a description or an example of how to do the hard part, you should be able to take your JavaScript knowledge and add the missing pieces. If you are not that familiar with JavaScript, do yourself a favor and look at some introductory material (I like this for JavaScript in Acrobat: Beginning JavaScript for Adobe Acrobat ).

Looking at your script, you already have most of the functionality in place. You should be able to change the output (assuming that your field can take a string and is not just a numeric field), by changing just the last line:

Change "event.value = totalY / total;" to the following:

event.value = totalY + " of " + total;

For easier readability, you may want to reformat the last two lines to this:

if (total==0)

    event.value = ""; 

else

    event.value = totalY + " of " + total;

Translate
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
Explorer ,
Jun 29, 2016 Jun 29, 2016
LATEST

It worked. Thanks Karl!

Creating PDF forms is only one responsibility in the entire process lifecycle. I am just learning how to do this, but I learn fast. Sometimes, I will need the entire script until I get better at it. Unfortunately, I only do this type of work every so often.

Thank you so much.

Translate
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