Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How can I know which radio button 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")
How do I know which one is selected?
by

3 Answers

Bharatv4tg1
On the off chance that you as of now have a reference to a radio catch bunch, for instance:
var myRadio = $("input[name=myRadio]");

Utilize the filter() fucntion, not find(). (find() is for finding kid/relative components, while filter() look through high level components in your determination.)
var checkedValue = myRadio.filter(":checked").val();

This answer was initially remedying another answer that suggested utilizing find(), which appears to have since been changed. find() could, in any case, be valuable for the circumstance where you previously had a reference to a compartment component, however not to the radio catches, e.g.:
var form = $("#mainForm");
...
var checkedValue = form.find("input[name=myRadio]:checked").val();
MounikaDasa
This should work:

$("input[name='radioName']:checked").val()
Note the "" usaged around the input:checked and not '' like the Peter J's solution
sandhya6gczb
To get the value of the selected radio name item with a form id my form

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

Login / Signup to Answer the Question.