3 Replies Latest reply on Sep 12, 2017 9:31 PM by gkaiseril

# Counting number of Yes, No or NA Radio Buttons

I have a PDF form with 20 radio button groups with Values of "Yes", "No" and "NA". I need a script to count the number of each value selected by the user.

• ###### 1. Re: Counting number of Yes, No or NA Radio Buttons

You need to create a custom JavaScript calculation and test each field's value and count the ones that meet your criteria.

// create a variable to count "Yes" values

var nYes = 0;

// create a variable to count "No" values

var nNo = 0;

// create a variable to count "NA" values

var nNA = 0;

// create a variable to count "Off" values - unselected items

var nOff = 0;

// get the field value  for Check Box1

var cValue = this.getField("Check Box1").value;

// test the value and count as needed

if(cValue == "Yes") nYes++; // increment counter

if(cValue == "No") nNo++; // increment counter

if(cValue == "NA") nNA++; // increment counter

if(cValue == "Off") nOff++; // increment counter

// get the field value  for Check Box2

cValue = this.getField("Check Box2").value;

// test the value and count as needed

if(cValue == "Yes") nYes++; // increment counter

if(cValue == "No") nNo++; // increment counter

if(cValue == "NA") nNA++; // increment counter

if(cValue == "Off") nOff++; // increment counter

// report results

var cMsg = "Yes answers: " + nYes + "\n";

cMsg = cMsg + "No answers: " + nNo + "\n";

cMsg = cMstg+ "NA answers: " + nNA + "\n";

cMsg = cMstg+ Offo answers: " + nOff + "\n";

You could simplify this by using a loop to process each field.

• ###### 2. Re: Counting number of Yes, No or NA Radio Buttons

I have a similar question. How to make a simple Yes and No check boxes on website that also give the total number of the checked Yes or No totals in separate totals boxes that stays on the website for the next visitors to add to it.

• ###### 3. Re: Counting number of Yes, No or NA Radio Buttons

The code provided is for use in an a PDF form file not a web page.