Skip to main content
Participant
April 20, 2021
Answered

How does one sum a specific choice from a series of groups of radio buttons?

  • April 20, 2021
  • 1 reply
  • 1846 views

I have a list of about 25 questions.  They are radio buttons with the choice of Yes, No, Maybe.

Fields are set up as:

Q1 is set up as  Group1 (Choice1"Yes", Chioce2"No", Choice3"Maybe")

Q2 is set up as Group2 (Choice1"Yes", Chioce2"No", Choice3"Maybe")

All the way to Q25

Im trying to add all of the Yes (or choice1) answers in one field, all of the No (of choice2) answers another field and all of the Maybe (choice3) answers in another field.

When i try to calculate using the sum function i'm only able to choose groups and dont have the option to specify the choice fields.

Does anyone have any sugestions on how to add up the specific choice fields?  would be very much appreciated!!!

This topic has been closed for replies.
Correct answer Nesa Nurani

Lets say your 3 fields to show sum are called 'Yes', 'No' and 'Maybe', use this script as calculation script of 'Maybe' field:

var y = 0;
var n = 0;
var m = 0;
for ( var i=1; i<=25; i++){
if(this.getField("Group"+i).value == "Choice1")y++;
if(this.getField("Group"+i).value == "Choice2")n++;
if(this.getField("Group"+i).value == "Choice3")m++;
if(y == 0 && n == 0 && m == 0){
this.getField("Yes").value = "";
this.getField("No").value = "";
event.value = "";}
else{
this.getField("Yes").value = y;
this.getField("No").value = n;
event.value = m;}}

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
April 20, 2021

Lets say your 3 fields to show sum are called 'Yes', 'No' and 'Maybe', use this script as calculation script of 'Maybe' field:

var y = 0;
var n = 0;
var m = 0;
for ( var i=1; i<=25; i++){
if(this.getField("Group"+i).value == "Choice1")y++;
if(this.getField("Group"+i).value == "Choice2")n++;
if(this.getField("Group"+i).value == "Choice3")m++;
if(y == 0 && n == 0 && m == 0){
this.getField("Yes").value = "";
this.getField("No").value = "";
event.value = "";}
else{
this.getField("Yes").value = y;
this.getField("No").value = n;
event.value = m;}}

Participant
April 20, 2021

Thanks Nesa. I put that script in but its not calculating.   Im at a loss as to why

Nesa Nurani
Community Expert
Community Expert
April 20, 2021

Check javascript for error. Check that all your fields are named correctly and that they have correct choices, if that doesn't help share your file so I can see whats going on.