how can i print the output of radio input? | SoloLearn: Learn to code for FREE!

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; }

7/8/2020 4:40:36 PM

nknown

8 Answers

New Answer

+2

+4

nknown Use this var radios = document.getElementsByName('gender');   for (var radio of radios) {     if (radio.checked) {       alert(radio.value);     }   }

+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.

+3

nknown Don't ask same question twice without any interval of time https://www.sololearn.com/Discuss/2380195/?ref=app

+1

nknown I gave you example. You can replace alert.

+1

AJ Anant - C#/Java Challenger really thank sir.It took me about four hours to solve.

0

𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 sorry .connection error

0

AJ Anant - C#/Java Challenger it's print as alert box but when I try to print on <p> ,it isn't work.