jQuery On Change Radio value

Getting value from selected radio field using jQuery isn’t tough though. To get the selected radio field value we could use the following code replacing the name radio_input to your desired

<script type="text/javascript">
    var selected_radio_value = $("input[name='radio_input']:checked").val();
</script>

We have used radio name, because not each radio will have the same ID logically. However, it could be also retrieved with class name.

<script type="text/javascript">
    var selected_radio_value = $(".my_radio_input:checked").val();
</script>

To get radio button value when they have changed you can bind on jQuery change event

<script type="text/javascript">
$("input[name='radio_button']").change(function(){
    var selected_radio = $("input[name='radio_input']:checked").val();
    if (selected_radio == 'hello_world'){
        return true;
    }
    else
    {
        return false;
    }
});
</script>

Find some more examples on http://api.jquery.com/radio-selector/ and http://forum.jquery.com/.

Topic

Discussion