Skip to main content
dianeh44612240
Participant
April 28, 2022
Question

Multiple Checkboxes - AT LEAST one required

  • April 28, 2022
  • 2 replies
  • 431 views

I have a form that has several radio button and checkboxes.  I do not want the form to be submitted until all the required fields and at least one checkbox are checked.  Once complete, the form will be emailed to me.

 

The required fields work like a charm.  However, I can't seem to get the checkboxes to do the same....checked or unchecked, the form still attempts to email me (see example).  

 

I've read several older posts that were shared but I'm missing something.  Any advice would be greatly appreciated. 

 

Below is the script:

 

var emptyFields = [];
for (var i=0; i<this.numFields; i++) {
var f = this.getField(this.getNthFieldName(i));
if (f!=null && f.type!="button" && f.required && f.valueAsString==f.defaultValue) {
emptyFields.push(f.name);
}
}
if (emptyFields.length>0) {

app.alert("You must fill in the following fields:\n" + emptyFields.join("\n"));

} else this.mailDoc({cTo: "diane.hands@wellstone.com",cSubject: "Staff Enrollment Form"});

 

 

 

 

 

This topic has been closed for replies.

2 replies

dianeh44612240
Participant
May 6, 2022

The boxes are named "Check Box21.0.0 through Check Box21.0.16". 

try67
Community Expert
Community Expert
May 6, 2022

Before this line:

 

if (emptyFields.length>0) {

 

Add this:

 

var isBoxChecked = false;
for (var i=0; i<=16; i++) {
	if (this.getField("Check Box21.0."+i).valueAsString!="Off") isBoxChecked = true;
}
if (isBoxChecked==false) emptyFields.push("At least one box from Check Box21.0.1 - Check Box21.0.16");

 

You can adjust the description of the check-boxes group (the text in the last line) to something more meaningful, of course.

try67
Community Expert
Community Expert
April 28, 2022

It has to be done separately. What are the names of those check-boxes?