AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



html-javascript: How to get selected radio button value?

Please give me example to get the selected radio button value.

html x 24
javascript x 33
Posted On : 2016-05-02 23:30:08.0
profile Saksham Kumar - anyforum.in Saksham Kumar
73433932708
up-rate
2
down-rate

Answers


In javascript checked property of radio button can be used to determine whether it´s selected or not.

CheckedRadio.html:
-------------------------------------------------------
<html>
<title>CheckedRadio- anyforum.in</title>
<body>
<form name="myform">
A: <input type="radio" name="answer" value="A"/><br/>
B: <input type="radio" name="answer" value="B"/><br/>
C: <input type="radio" name="answer" value="C"/><br/>
D: <input type="radio" name="answer" value="D"/><br/>
<input type="button" value="submit" onclick="getSelected()"/>
</form>
<script type="text/javascript">
function getSelected(){
var radio=document.getElementsByName("answer");
for(var i=0;i<radio.length;i++){
if(radio[i].checked){
alert(radio[i].value);
}
}
}
</script>
</body>
</html>

Posted On : 2016-05-02 23:38:38
Satisfied : 1 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523188241268
Reply This Thread
up-rate
4
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in