I'm doing a validation code for at least one checkbox in javascript.
I relied on this example
Since it allows to stop the process until validation is done.
I can not get the code to work.
function validate(e) {
var formulario = document.form;
for (var i = 0; i < form.choice.length; i++) {
if (form.choice[i].checked === 0) {
alert ('debes seleccionar al menos una opción');
if (e.preventDefault) {
e.preventDefault();
} else {
e.returnValue = false;
}
}
}
}
<form name = "form" onsubmit = "validate(event, this);">
<input type = "checkbox" name = "chice" value = "valor1" />
<input type = "checkbox" name = "chice" value = "valor2" />
<input type = "checkbox" name = "chice" value = "valor3" />
<input type = "checkbox" name = "chice" value = "valor4" />
<input type = "submit" />
</form>