Tuesday, February 14, 2012

Get Radio Button value using jQuery

Here’s small piece of code to get the value of a checked or selected radio button out of a group of radio buttons.
var selValue = $('input[name=rbnNumber]:checked').val(); 
In above code, rbnNumber is name of the radio group.

Demo

HTML Code:


jQuery Code:


Result:

See Complete Code
You can also get the value of individual radio button using it's ID as selector.
var selValue = $('#rbnNumber:checked').val(); 
If you want to get ID of selected radio button out of group of radio button, then below code will work.
var selValue = $('input[name=rbnNumber]:checked').attr('id'); 
See Result, jQuery and HTML code below:



Feel free to contact me for any help related to jQuery, I will gladly help you.