I have a problem in validating whether at least one checkbox is checked or not.
the same code is being used for a different form and its working perfectly but I can't figure why it doesn't on this form.
this is the HTML and jquery code
if(jQuery('#MOTForm input[type=checkbox]:checked').length == 0) {
alert("1");
valid = valid && false;
$("#MOTFORMERROR").css('color', 'red');
$("#MOTFORMERROR").html("*Choose at least one");
}else{
$("#MOTFORMERROR").html("");
}
<td style="width: 10%;" rowspan="3">
<div style="padding-left:5px;">
<form id="MOTForm">
<input name="" type="checkbox" class="form-check-input"/> HEMS<br />
<input name="" type="checkbox" class="form-check-input"/> EMS<br />
<input name="" type="checkbox" class="form-check-input"/> Walk-in<br />
</form>
<p id="MOTFORMERROR"></p>
</div>
</td>
the if statement is what being run all the time not the else statement even if one or all checkboxes are checked!
Aucun commentaire:
Enregistrer un commentaire