Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the currently selected radio button in a jquery ui buttonset without binding to click

Tags:

I have radio buttons like this:

<div id="radio">     <input type="radio" id="radio1" name="radioOption" /><label for="radio1">Choice 1</label>     <input type="radio" id="radio2" name="radioOption" checked="checked" /><label for="radio2">Choice 2</label>     <input type="radio" id="radio3" name="radioOption" /><label for="radio3">Choice 3</label> </div> 

And apply the button set like this:

$(function () {     $("#radio").buttonset(); }); 

I need to get the selected radio button without binding to the click event.

like image 878
Dave Avatar asked Jan 18 '12 10:01

Dave


People also ask

How to get selected in radio button?

To get the value of selected radio button, a user-defined function can be created that gets all the radio buttons with the name attribute and finds the radio button selected using the checked property. The checked property returns True if the radio button is selected and False otherwise.


1 Answers

Damn just realised my selecter had a typo, but if it helps anyone else:

If you dont want to use the click event, which I didn't you could do the following: If you're looking for the element it self use:

$("#radio :radio:checked"); 

If you're looking for the id of the element use:

$("#radio :radio:checked").attr('id'); 

If you're need to know what the text of the value selected then this should work:

$("#radio :radio:checked + label").text(); 
like image 61
Dave Avatar answered Nov 07 '22 03:11

Dave