How to perform validation for a radio button group (one radio button should be selected) using jQuery validation plugin?
相关问题
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
- Include empty value fields in jQuery .serialize()
- Disable Browser onUnload on certain links?
- how to get selected text from iframe with javascri
use the following rule for validating radio button group selection
myRadioGroupName is the value you have given to name attribute
You can also use this:
and simply add this rule
Mention how to add rules.
Another way to validate is like this.
I hope my example will help you
With newer releases of jquery (1.3+ I think), all you have to do is set one of the members of the radio set to be required and jquery will take care of the rest:
The above would require at least 1 of the 3 radio options w/ the name of "my options" to be selected before proceeding.
The label suggestion by Mahes, btw, works wonderfully!
code for radio button -
and jQuery code-
As per Brandon's answer. But if you're using ASP.NET MVC which uses unobtrusive validation, you can add the data-val attribute to the first one. I also like to have labels for each radio button for usability.