How to perform validation radiobutton. failed to perform the radio button validation when use button type button instead input type submit.
1 Answer
Try this:
$(document).ready(function() {
$('#myform').validate({
rules:{
foobar :
{
required: true
}
}
});
});
There are so many issue with your code.
- You have to give similar name for all the radio resides in one group, otherwise they work like checkbox.
- Jquery validation works on name for the specific element. So name is mandatory.
4 Comments
user3835327
Noted. but how can i show the error message with my own message by using html dom innerHTML ? for example document.getElementById("errMsg").innerHTML = "Please check!";... by using the solution you provided
user3835327
Thank alot @Mayank Pandeyz
Mayank Pandeyz
Happy coding :)
Kirill A
Radio buttons won't validate if they have property display:none. Option "ignore" resolves this problem. $(document).ready(function() { $('#form').validate({ ignore:''", rules:{ foobar : "required" } }); });