Radio button validation in form | SoloLearn: Learn to code for FREE!

+1

Radio button validation in form

Can anyone tell me how can I validate radiobutton for gender in form validation https://code.sololearn.com/W56opd7Y1vNK/?ref=app

8/31/2020 5:16:53 PM

Psycho

3 Answers

New Answer

+1

There is nothing to validate for radio buttons on forms since only one can be selected and any single selection is valid. The easiest way to do this is to auto select a default value by using the checked attribute e.g. <input type="radio" name="gender" value="male" checked>Male If the user does not change the default value then the entry is still valid. See... https://www.w3schools.com/tags/att_input_checked.asp HTML5 form controls have the ability to validate themselves without the need for JavaScript. See... https://developer.mozilla.org/en-US/docs/Learn/Forms/Form_validation#Using_built-in_form_validation

0

If the name for all radio will be same you can select only one out of them.