How to perform validation for a radio button group (one radio button should be selected) using jQuery validation plugin?
+11
A:
Example on the validation demo pages
http://jquery.bassistance.de/validate/demo/radio-checkbox-select-demo.html
redsquare
2008-11-10 11:08:56
+4
A:
use the following rule for validating radio button group selection
myRadioGroupName : {required :true}
myRadioGroupName is the value you have given to name attribute
Mahes
2009-12-03 21:54:03
Note that if you want to control the position of the label, you can provide your own error label where you want it with the text you would like: <label for="myRadioGroupName" class="error" style="display:none;">Please choose one.</label>
Tom
2010-04-09 02:02:06
A:
The given link does not work anymore. Is the bassistance.de site taken off now? Has the plugin been moved over to a new developer site? Or is it being discontinued?
eFrontier
2010-02-08 06:27:43
it's online. the plugin is definitely not being discontinued: it's one of the most popular!
pixeline
2010-04-16 11:29:46
+1
A:
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:
<input type="radio" name="myoptions" value="blue" class="required"> Blue<br />
<input type="radio" name="myoptions" value="red"> Red<br />
<input type="radio" name="myoptions" value="green"> Green
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!
Brandon Rome
2010-07-27 21:01:26
A:
You can also use this:
<fieldset>
<input type="checkbox" name="myoptions[]" value="blue"> Blue<br />
<input type="checkbox" name="myoptions[]" value="red"> Red<br />
<input type="checkbox" name="myoptions[]" value="green"> Green<br />
<label for="myoptions[]" class="error" style="display:none;">Please choose one.</label>
</fieldset>
and simply add this rule
rules: {
'myoptions[]':{ required:true }
}
Haider Abbas
2010-08-22 03:48:35