Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to validate radio button without javascript?

I have used radio button for gender as follow:-

<td><input type="radio" name="gender" value="male" checked required="required"> Male<br>
  <input type="radio" name="gender" value="female"> Female<br>
  <input type="radio" name="gender" value="other"> Other</td>

but this "required" validation is not working how to put validation on it without using JavaScript.

like image 349
Smit Saraiya Avatar asked Dec 19 '22 14:12

Smit Saraiya


1 Answers

Required is a HTML5 attribute for input control validation, you can add the required attribute at end of tag and if you want Gender radio button checked by default, you can add checked.

This would checked the radio button default when page loads,

<input type="radio" name="gender" value="male" checked required/> Male

This will work, so we no need to go for JS validation.

like image 141
KickyTrick Avatar answered Jan 08 '23 21:01

KickyTrick