Get value of radio button using jQuery

Posted: June 8th, 2009 | Author: admin | Filed under: Javascript | Tags: , | 2 Comments »

Here’s a tutorial on how to get the value of a checked or selected radio button out of a group of radio buttons:

...
<input type="radio" name="sample" value="1" />
<input type="radio" name="sample" value="2" checked="checked" />
<input type="radio" name="sample" value="3" />
...

//javascript code

<script type="text/javascript">
<!--
    // displays the selected radio button in an alert box
    alert($('input[name=sample]:checked').val())
-->
</script>