View Tutorial Metadata Edit Content Revision History Add New Tutorial Add to Watchlist How to get the value of the selected radio button in jQuery

How to get the value of the selected radio button with jQuery

If you want to get the value of the selected radio button from a structure like this :

<input type="radio" name="radio_btn" value="value1" /> Option 1
<br />
<input type="radio" name="radio_btn" value="value2" /> Option 2

You can use the following jQuery code :

// Get the value
var selected = $('[name=radio_btn]:checked').val();
// Display it
alert(selected);

That was all :) Pretty simple, eh?

Talk icons discuss – in the article above, point your mouse over them to reply.
Can't find a relevant Talk icon for what you have to say? See how you can add one...
Note: All the talks and replies are also listed below.


Add a new discussion topic (Only if you don't find it above, duplicates will be removed)


Rating: (0+, 0-) In: jQuery