HiveBrain v1.2.0
Get Started
← Back to all entries
snippetjavascriptCritical

How can I know which radio button is selected via jQuery?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
howbuttonjqueryviaradioselectedcanwhichknow

Problem

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?

Solution

To get the value of the selected radioName item of a form with id myForm:

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


Here's an example:



$('#myForm input').on('change', function() {
alert($('input[name=radioName]:checked', '#myForm').val());
});




Choose radioName
1

2

3


Code Snippets

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

Context

Stack Overflow Q#596351, score: 4306

Revisions (0)

No revisions yet.