Skip to main content
Henry.Ong
Inspiring
September 16, 2018
Answered

How to count all the "Yes" answers from 20 questions?

  • September 16, 2018
  • 5 replies
  • 4793 views

I have created a PDF form with 20 questions answerable with "Yes" and "No".

At the end of the form, I want to count the number of all "Yes" answers.

Thanks in advance.

Henry

This topic has been closed for replies.
Correct answer try67

Your fields are not named anything like what you described...

For the first group use this code:

var total = 0;

for (var i=11; i<=15; i++) {

    var fname = "Question" + i;

    var f = this.getField(fname);

    if (f.valueAsString=="Yes") total++;

}

event.value = total;

5 replies

Henry.Ong
Henry.OngAuthor
Inspiring
September 18, 2018

Thanks!

The script provided is working.

Henry.Ong
Henry.OngAuthor
Inspiring
September 18, 2018

Sorry for this shortcoming on my part as this is the first time I will be using Dropbox.

Please try this public link in Dropbox ...

https://www.dropbox.com/s/us7m23vs4af1tay/Sample.pdf?dl=0

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
September 18, 2018

Your fields are not named anything like what you described...

For the first group use this code:

var total = 0;

for (var i=11; i<=15; i++) {

    var fname = "Question" + i;

    var f = this.getField(fname);

    if (f.valueAsString=="Yes") total++;

}

event.value = total;

Henry.Ong
Henry.OngAuthor
Inspiring
September 18, 2018

Please find the link below

https://www.dropbox.com/h

If you cannot access the link, here is a sample

Section 1

Fieldname:    Question11               Text

                      Question12               Text

                      Question13               Text

                      Question14               Text

                      Question15               Text

                      Section1YesCount    Numeric

Fieldnames Question11 to Question15 should be answerable by "Yes" or "No"

What I want to happen is for Section1YesCount to automatically compute the number of "Yes" from Question11 to Question15.

Example:

Question11      Yes

Question12      Yes

Question13      No

Question14      No

Question15      Yes

Therefore, Section1YesCount should be equal to 3.

Bernd Alheit
Community Expert
Community Expert
September 18, 2018

This is not a public link.

try67
Community Expert
Community Expert
September 16, 2018

Then you can do it like this:

var total = 0;

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

    var fname = "ANSWER" + ((i<10) ? "0"+i : i);

    var f = this.getField(fname);

    if (f.valueAsString=="Yes") total++;
}

event.value = total;

Use this code as the custom calculation script of the field where you want to show the total number of Yes boxes ticked.

Henry.Ong
Henry.OngAuthor
Inspiring
September 17, 2018

Hi Try67,

I cannot seem to have this to work.

Here is the sample file with limited number of questions.

Thanks

try67
Community Expert
Community Expert
September 16, 2018

What are the names of the fields?

Henry.Ong
Henry.OngAuthor
Inspiring
September 16, 2018

The name of the fields are ANSWER01 to ANSWER30

Bernd Alheit
Community Expert
Community Expert
September 17, 2018

Are there 20 or 30 questions?