How To Get The Selected RadioButton From A List Of Element IDs Using jQuery

I've been doing some work with jQuery lately and now that I've begun digging into it am truly impressed at how much you can do with it so easily. Here's a quick line of code that will take a string of element IDs belonging to RadioButtons, find the one that's selected, and display an alert box with it's value:

alert("Selected radio button value: " + $(radioButtonIds).filter(":checked").get(0).value);

The format of the string containing the RadioButton IDs would look something like this:

"#rdoFirstChoice, #rdoSecondChoice, #rdoThirdChoice"

Comments

Popular posts from this blog

A Generic Method Using HttpClient to Make a Synchronous Get Request

The Cause and Solution for the "System.Runtime.Serialization.InvalidDataContractException: Type 'System.Threading.Tasks.Task`1[YourTypeHere]' cannot be serialized." Exception

How To Mock Out Child Components In Unit Tests of Angular 2 Code