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"});
