Organizational Research By

Surprising Reserch Topic

How can I get which radio is selected via jQuery?


I have two radio buttons and want to post the value of the selected one, how can I get the value with jQuery?

I can get all of them like this:

$("form :radio")

But how do I know which one is selected?


asked May 20, 2015 in JAVASCRIPT by rahulgii
0 votes
20 views



Related Hot Questions

3 Answers

0 votes

To get the value of the selected radioName item of a form called 'myForm':

$('input[name=radioName]:checked', '#myForm').val()

Here's an example: Fiddle

answered May 20, 2015 by rahulgii
0 votes

Use this..

$("#myform input[type='radio']:checked").val();
answered May 20, 2015 by rahulgii
0 votes

 you already have a reference to a radio button group, for example:

var myRadio = $('input[name=myRadio]');

Use the filter() function, not find(). (find() is for locating child/descendant elements, whereasfilter() searches top-level elements in your selection.)

var checkedValue = myRadio.filter(':checked').val();

Note: This answer was originally correcting another answer that recommended using find(), which seems to have since been changed. find() could still be useful in the situation where you already had a reference to a container element, but not to the radio buttons, e.g.:

var form = $('#mainForm');
...
var checkedValue = form.find('input[name=myRadio]:checked').val();
answered May 20, 2015 by rahulgii

...