Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Can I get the text of the selected radio in the radio groups

as said in the title for example:

<input id="User_Type_0" type="radio" name="User_Type" value="1" checked="checked" />
<label for="User_Type_0">User1</label>
<input id="User_Type_1" type="radio" name="User_Type" value="2" />
<label for="User_Type_1">User2</label>

how can I get the text:User 1

like image 910
Michael Avatar asked Jan 25 '10 13:01

Michael


2 Answers

$('input:radio:checked').siblings('label:first').html()


UPDATE:

As pointed out by Victor in the comments section the previous selector will always select the first label. The next function should work:

$('input:radio:checked').next('label:first').html()
like image 61
Darin Dimitrov Avatar answered Oct 12 '22 14:10

Darin Dimitrov


how about this?

var forLabel = $('input:radio:checked').attr("id");
$("label[for='" + forLabel + "']").text();
like image 40
Natrium Avatar answered Oct 12 '22 15:10

Natrium