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; }
8 Answers
+ 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.
+ 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.