0

how can i print the output of radio input?

here is my html code; <tr> <td>Gender</td> <td> <div class="a"> <input type="radio" name="gender" value="male" id="Male">male <input type="radio" name="gender" value="female" id="Female">female </div> </td> <p>gender : <span id="userGender"></span></p> here is my javascript code: var gender= document.getElementsByClassName("a").value; if(document.getElementsByClassName("Male").checked){ var gender_value = document.getElementById("Male").value; document.getElementById("userGender").innerHTML = gender_value; }

8th Jul 2020, 4:40 PM
Zwe Thu
Zwe Thu - avatar
8 Answers
+ 4
nknown Use this var radios = document.getElementsByName('gender');   for (var radio of radios) {     if (radio.checked) {       alert(radio.value);     }   }
8th Jul 2020, 4:48 PM
A͢J
A͢J - avatar
+ 4
nknown Good it solved but don't waste too much time on a simple thing. Just try till only 30 minutes. If you don't get solution within that times you should ask.
8th Jul 2020, 5:25 PM
A͢J
A͢J - avatar
+ 1
nknown I gave you example. You can replace alert.
8th Jul 2020, 5:13 PM
A͢J
A͢J - avatar
+ 1
AJ Anant - C#/Java Challenger really thank sir.It took me about four hours to solve.
8th Jul 2020, 5:18 PM
Zwe Thu
Zwe Thu - avatar
0
AJ Anant - C#/Java Challenger it's print as alert box but when I try to print on <p> ,it isn't work.
8th Jul 2020, 5:04 PM
Zwe Thu
Zwe Thu - avatar