Issues With Javascript Validation Of Radio Buttons On Php Form
This is the code for the php file containing the form with radio buttons:
Solution 1:
functionRegValidate(Tester) {
if ($(":radio[name=w1]:checked").toArray().length == 0) {
alert('nothing selected');
returnfalse;
}
}
Solution 2:
you have an error, your input doesn't have ID or CLASS, so add to all of the input radio class='w1'
and try the next code:
if ($(".w1 option:selected").length<1)
alert ('nothing selected');
also take a look to this post: Check if option is selected with jQuery, if not select a default
Solution 3:
do these things:
<inputtype='radio'class='w1' name='w1' value='1'>1<br>
<inputtype='radio'class='w1' name='w1' value='2'>2<br>
<inputtype='radio'class='w1' name='w1' value='3'>3<br>
And in js:
Latest edit:
if ( $(':radio[class=w1]').attr('checked') != 'checked' ) {
alert('Radio not checked');
}
Post a Comment for "Issues With Javascript Validation Of Radio Buttons On Php Form"