Why the radio button is not working? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

Why the radio button is not working?

I don't know if I made an error or what. When clicking in the button "Yes" and "No", why am I able to click both Yes and No. What mistake is there to make able to choose both button. Please help me. I want to make it clickable for just one button. https://sololearn.com/compiler-playground/WYb16fvI6l1q/?ref=app

14th May 2024, 1:15 PM
Mohit Gautam
3 Antworten
+ 2
Wilbur Jaywright Friend is not a valid attribute, but doesnt invalidate the tag itself. It can be read from JS for better usability. Often youd add something like “data-“ in front. For example <input type=“radio” data-friend=“yes”>. The error in this case is, that the input fields arent wrapped into a form and dont have a name attributr. Try adding a “<form>” in front of the inputs and a “</form” after them. Then you also have to add the same name attribute, for example: <input type=“radio” name=“friend-answer”> Feel free to let me know if this helped you or if you still have questions
14th May 2024, 3:11 PM
Brentspine
Brentspine - avatar
+ 1
I don’t think “friend” is a valid parameter of the radio button tag. What do you want to do is set the name parameter of both buttons to “friend” to make them affect the same variable, and then set the value parameter to “want” or “don’t want” for each (right now they are both “want” which wouldn’t work even if the paeameters were correct).
14th May 2024, 1:32 PM
Wilbur Jaywright
Wilbur Jaywright - avatar
+ 1
Same question here. Solution use name attributes. https://www.sololearn.com/Discuss/3276684/?ref=app
14th May 2024, 8:36 PM
Chris Coder
Chris Coder - avatar