jQuery get value of selected radio button jQuery get value of selected radio button jquery jquery

jQuery get value of selected radio button


Just use.

$('input[name="name_of_your_radiobutton"]:checked').val();

It is that easy.


First, you cannot have multiple elements with the same id. I know you said you can't control how the form is created, but...try to somehow remove all the ids from the radios, or make them unique.

To get the value of the selected radio button, select it by name with the :checked filter.

var selectedVal = "";var selected = $("input[type='radio'][name='s_2_1_6_0']:checked");if (selected.length > 0) {    selectedVal = selected.val();}

EDIT

So you have no control over the names. In that case I'd say put these radio buttons all inside a div, named, say, radioDiv, then slightly modify your selector:

var selectedVal = "";var selected = $("#radioDiv input[type='radio']:checked");if (selected.length > 0) {    selectedVal = selected.val();}


Simplest way to get the selected radio button's value is as follows:

$("input[name='optradio']:checked").val();

No space should be used in between selector.