Skip to main content
Monteigo99
Inspiring
June 29, 2016
Answered

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

  • June 29, 2016
  • 1 reply
  • 716 views

(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

This topic has been closed for replies.
Correct answer Karl Heinz Kremer

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;

1 reply

Karl Heinz  Kremer
Community Expert
Community Expert
June 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

Monteigo99
Inspiring
June 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;

Karl Heinz  Kremer
Community Expert
Karl Heinz KremerCommunity ExpertCorrect answer
Community Expert
June 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;