skip to content

Getting the value of a selected radio button out of a radio group in jQuery

January 29th, 2009

Just a quick tip, I needed to get the value of the selected radio button from a radio group using jQuery. While several custom selectors are available for forms, there isn’t a simple way to do it that I could find. I ended up using a solution that I quite like, and wanted to share.

$("input[name=radio_group]:checked").val(); 

Have I mentioned that I love jQuery?

Edit: This entry was directly attacked by the robots, and all comments were lost. Please leave one again if you left it earlier, and accept my sincerest of apologies.

 

This entry was made on January 29th, 2009 @ 15:22 and filed into How-To, Javascript.

Comments

Steven Hambleton wrote on February 12th, 2009 @ 15:15

If you wanted to compare a radio button value and do something like show an input text field for one of the radio buttons then you can use this -

$("input:radio[name=referredby]").click(function() {
if ( $(this).val() == 'Other' {
    
$("#referredby_other").show("fast");
}
else {
    
$("#referredby_other").hide("fast");  }
}
); 

Post a Comment

Sorry, comments are automatically closed after 45 days, or sooner if one entry gets targetted by spammers. Why not contact me directly?