Skip to main content
Participant
December 1, 2023
Question

Trying to count total number of radio buttons selected with different values

  • December 1, 2023
  • 1 reply
  • 301 views

I have multiple questions with 5 radio buttons valued from 1-5. I am trying to have a textbox calculate the total number of 4's and 5's that were selected out of all questions. 

 

I am able to calculate all of the 4's using this below. any suggestions on how to add the 5's to get the total of both columns? 

 

var testFor = "4";
var groups = this.getField("Group");
var ar = groups.getArray();
var cnt = 0;
for (var i=0; i<ar.length; i++) {
if (ar[i].value == testFor) {
cnt++;
}
}
event.value = cnt;

This topic has been closed for replies.

1 reply

Nesa Nurani
Community Expert
Community Expert
December 1, 2023

Use this:

var total = 0;
var groups = this.getField("Group").getArray();
for (var i=0; i<groups.length; i++) {
if (groups[i].value == 4 || groups[i].value == 5)
total++;}
event.value = total;