Skip to main content
polishgerbils
Participant
September 19, 2017
Answered

Calculation Script for Checkboxes

  • September 19, 2017
  • 1 reply
  • 516 views

I am looking to expand on another calculation script I am using for counting check boxes.

My PDF Document has a series of questions with which a "Yes" "No" or "N/A" option can be checked. The check boxes are named in the following format:

Yes.Q1, Yes.Q2, Yes.Q3...

No.Q1, No.Q2, No.Q3...

Na.Q1, Na.Q2, Na.Q3...

This is what I am using in order to count "Yes" answers on the checklist in a field below:

var nSum = 0;var aCkFlds = this.getField("Yes").getArray();for(var i=0;i<aCkFlds.length;i++){if(aCkFlds.isBoxChecked(0))nSum++;}event.value = nSum;

This works great for that. I want to expand the script for another field in which it will add the "Yes" and "No"  in order to get a count of all "Applicable Items" in the checklist.

Any assistance would be appreciated.

This topic has been closed for replies.
Correct answer try67

This should do the trick:

var nSum = 0;

var yesFields = this.getField("Yes").getArray();

for (var i=0; i<yesFields.length; i++){

    if (yesFields.isBoxChecked(0)) nSum++;

}

var noFields = this.getField("No").getArray();

for (var i=0; i<noFields.length; i++){

    if (noFields.isBoxChecked(0)) nSum++;

}

event.value = nSum;

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
September 19, 2017

This should do the trick:

var nSum = 0;

var yesFields = this.getField("Yes").getArray();

for (var i=0; i<yesFields.length; i++){

    if (yesFields.isBoxChecked(0)) nSum++;

}

var noFields = this.getField("No").getArray();

for (var i=0; i<noFields.length; i++){

    if (noFields.isBoxChecked(0)) nSum++;

}

event.value = nSum;