At HTML, Radio code output is choosing both option. Why? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

At HTML, Radio code output is choosing both option. Why?

<form> Username: <input action="url" method="GET" type="text" name="Username"/><br/> <br/> Password : <input type="password" name="Password" /> <br/> Do you like to save the Password or Username? <br/> <input type="radio" name="username"/> Username <br/> <input type="radio" name="password"/> Password <br/> </form> this is a code for Radio options. It should've choose only one option. but It is marking both of them simultaneously. Cheack box can do that but not Radio.

11th Sep 2017, 7:27 AM
Senjik Saif
Senjik Saif - avatar
1 Answer
+ 12
The radio control group multiple inputs using the name attribute. In this case it treat both radio inputs as separated group with different name which caused the problem. Therefore the proper way would be something like:- <input type="radio" name="saveField" value="Username" /> Username <br/> <input type="radio" name="saveField" value="Password"/> Password
11th Sep 2017, 7:33 AM
Zephyr Koo
Zephyr Koo - avatar