jqueryexample.com jQuery example - get checked radio button value - jqueryexample.com

jQuery example – get checked radio button value by jqueryexample

To find checked element value of radio button you can use the :checked selector along with the radio selector.
var selectedRadio = myRadios.filter(":checked");

$('input:radio:checked').each(function() {
    var value = $(this).val();
    // do something with radio or value
});

Example:
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var myRadios = jQuery("input[name=radio]");
function test(){
var selectedRadio = myRadios.filter(":checked");
jQuery("#RadioDiv").html('' + selectedRadio.val() );
}
window.setInterval( test, 100 );
});
</script>
</head>
<body>
<input type="radio" name="rad" value="1"/>
<input type="radio" name="radio" value="2"/>
<input type="radio" name="radio" value="3"/>
<div id="RadioDiv"></div>
</body>
</html>

Did you like this? Share it:

Discussion

No comments yet, be the first.

Leave a Comment