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
2 Respuestas
+ 6
let gender = document.querySelector('input[name="gender"]:checked').value;
And remember to set the value-attribute of the radio buttons.
+ 4
let gender = document.getElementsByName("gender")[0].value