Skip to main content
Known Participant
February 23, 2022
Answered

Need Script Help With Adding Yes/No Columns

  • February 23, 2022
  • 2 replies
  • 390 views

Im trying to add all the "Yes" and all the "No's" in each column. I'm using the following script that does not seem to work for me. 

var total = 0; for (var i=1; i<=60; i++) { var fields = this.getField("Check Box "+i).getArray(); for (var j in fields) { if (fields[j].valueAsString!="Off") total++; } } event.value = total;

I named the check boxes 1-60 the same for each question with a differant value in each (yes,no), so the end user can not check a yes and no for the same answer. Need a little help on this script. Not sure what I'm doing wrong. 

This topic has been closed for replies.
Correct answer try67

This script is not quite what you need. Use this:

 

var total = 0;
for (var i = 1; i <= 60; i++) {
	var f = this.getField("Check Box "+i);
	if (f.valueAsString=="yes")
		total++;
}
event.value = total;

 

Note that JS is case-sensitive, so "yes" and "Yes" are not the same thing...

2 replies

raypalmerAuthor
Known Participant
February 23, 2022

That did the trick. Thank you so much!!!!!!!

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
February 23, 2022

This script is not quite what you need. Use this:

 

var total = 0;
for (var i = 1; i <= 60; i++) {
	var f = this.getField("Check Box "+i);
	if (f.valueAsString=="yes")
		total++;
}
event.value = total;

 

Note that JS is case-sensitive, so "yes" and "Yes" are not the same thing...