Copy link to clipboard
Copied
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!!!
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("
Copy link to clipboard
Copied
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;}}
Copy link to clipboard
Copied
Thanks Nesa. I put that script in but its not calculating. Im at a loss as to why
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Your fields are named 'Group' not 'Q', so in script change "Q" with "Group" it was my mistake I thought your fields are named Q.
EDIT: I fixed code above.
Copy link to clipboard
Copied
Works like a charm! Thanks for yoru help Nesa!!! great appreciated
Copy link to clipboard
Copied
I'm trying to do something similar but with only 2 groups, yes and no.
When I label the groups, do I need to assign each group a Yes or No or will this still work with only using "choice1" or "choice2"?
What would a script look like for only 2 options? I removed the what i though needed to be removed from the above formula but nothing is happening. I'm not sure if Y & N are coming from the form or if we are just adding them
var y = 0;
var n = 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(y == 0 && n == 0){
this.getField("Yes").value = "";
this.getField("No").value = "";
event.value = "";}
else{
this.getField("No").value = n;
event.value = y;}}
Copy link to clipboard
Copied
Where did you put script?
You also need to change '25' to number of your fields.
You can leave "Choice1" and "Choice2" also it's case sensitive so 'choice1' and 'Choice1' is not same.
EDIT:
If you have fields "Yes" and "No" use script in one of those fields as 'Custom calculation script', make sure your groups are named in unison "Group1","Group2","Group3"...etc, replace red X with number of your groups:
var y = 0;
var n = 0;
for ( var i=1; i<=X; i++){
if(this.getField("Group"+i).value == "Choice1")y++;
if(this.getField("Group"+i).value == "Choice2")n++;}
this.getField("Yes").value = y == 0 ? "" : y;
this.getField("No").value = n == 0 ? "" : n;