Is there a way to validate a form instead of rules?
For example:
开发者_高级运维In the form there are 3 check boxes; i want to test if none of them is selected - in which case, return false and prevent the form from submitting
HTML :
<input type="checkbox" name="event[]" id="event" value="click">click<br>
<input type="checkbox" name="event[]" id="event" value="focus">focus<br>
<input type="checkbox" name="event[]" id="event" value="change">change<br>
jQuery :
$(document).ready(function()
{
$("form").submit(function()
{
var checked = $("input[@id=event]:checked").length;
if (checked == 0)
{
alert ("Please select at least one event");
return false;
}
else
{
return true;
}
});
});
Please do above steps and let me know if any.
submitHandler: function(form) {
if ( $('input[type="radio"]').is(':checked')==true){
form.submit() ;
}else{
alert("Please choose option");
}
}
精彩评论