4 Replies Latest reply on Jun 29, 2016 2:10 PM by Monteigo99

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

(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

• ###### 1. Re: Script for counting both Yes and No's in a column and returning the # of Yes's out of the Total

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

• ###### 2. Re: Script for counting both Yes and No's in a column and returning the # of Yes's out of the Total

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;

• ###### 3. Re: Script for counting both Yes and No's in a column and returning the # of Yes's out of the Total

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;
```
• ###### 4. Re: Script for counting both Yes and No's in a column and returning the # of Yes's out of the Total

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.