0

How to perform validation radiobutton. failed to perform the radio button validation when use button type button instead input type submit.

Demo : http://jsfiddle.net/05qm3r4m/63/

1 Answer 1

2

Try this:

$(document).ready(function() {
    $('#myform').validate({
    rules:{
        foobar : 
      {
        required: true
      }
    }
  });
});

Updated Fiddle

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.

Updated Fiddle with custom message

Sign up to request clarification or add additional context in comments.

4 Comments

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
Thank alot @Mayank Pandeyz
Happy coding :)
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" } }); });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.