+ 4
I supposed to take the value of two radio buttons with one id but it is not working correctly.
I have created two radio buttons with all the different values, but alas it is not working. <input type="radio" value="1" id="a" name="some"> <input type="radio" value="2" id="a" name="some"> <input type="radio" value="3" id="a" name="some"> <button onclick="myFun()"></button> function myFun(){ var myVariable = document.getElementById("a").value; // lets say i need value 2... if(myVariable == '2'){ alert(”done”); } code is correct but still it is not working? why? same problem give a upvote please....😕
6 Respostas
+ 3
ok sir let me try....
+ 2
brother it is still not working....😖
here is the code....
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<input type="radio" value="1" class="a" name="some">
<input type="radio" value="2" class="a" name="some">
<input type="radio" value="3" class="a" name="some">
<button onclick="myFun()">something</button>
<script>
function myFun(){
var ans = document.getElementsByClassName("a").value;
if(ans == '2'){
alert("done");
}
}
</script>
</body>
</html>
+ 1
id element must will be unique
+ 1
Use class attribute
+ 1
I don't know correct answer!((.😢
0
OK)