0

How do I change a variable based on radio input

As you can see in the attached code, I’ve already succeeded in making a name and age variable which changes depending on what you type/input. What I now need is to make the gender variable become either male or female depending on which radio button you click. If you know how to, I would be so grateful for your help!! https://code.sololearn.com/Wua0lgKMAYGq/?ref=app https://code.sololearn.com/Wua0lgKMAYGq/?ref=app

13th Feb 2023, 11:03 AM
Daisy
Daisy - avatar
2 Respostas
+ 6
let gender = document.querySelector('input[name="gender"]:checked').value; And remember to set the value-attribute of the radio buttons.
13th Feb 2023, 11:22 AM
Lisa
Lisa - avatar
+ 4
let gender = document.getElementsByName("gender")[0].value
13th Feb 2023, 11:26 AM
Jayakrishna 🇮🇳