I came accross a problem while I was trying to Get ASP.NET Radiobutton list Text using JQuery.

I used the JQuery method

$(‘#<%=RadioButtonList1.ClientID%>’).val();

but it was not returning selected value though same works for asp.net Dropdown list then I started searching over the internet but didn’t find any solution.

After searching for an hour I started looking for classic javascript to get the text of selected item in the Radio button list,
but all of the examples were giving me value of the selected item in the radio button list.

Onec I was struggling to get the text of selected item in asp.net dropdown list then found a solution which you can see in my post here
by combining the logic of this disablingenabling-aspnet-checkboxlist-items-using-javascritp
post with the code below I was able to find a solution to my problem.
Following code will give you the text of selected Item in an asp.net radio button list same also is true asp.net check box  list

function getRadioButtonText()
{
var elementId = ‘<%=RadioButtonList1.ClientID%>’;
var elementRef = document.getElementById(elementId);
var checkBoxArray = elementRef.getElementsByTagName(‘input’);

var checkedValue = ”;
var isChecked = false;

for (var i = 0; i < checkBoxArray.length; i++) {
if (document.getElementById(elementId + “_” + i.toString()).checked == true) {
var checkBoxRef = checkBoxArray[i];
var labelArray = checkBoxRef.parentNode.getElementsByTagName(‘label’);
checkedValue = labelArray[0].innerHTML;
alert(checkedValue);
Chekced = false;

break;
}
}

}

Please post a JQuery solution if you have .


I Wan to share this post:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • kick.ie
  • Live
  • MyShare
  • IndianPad
  • Reddit
  • StumbleUpon
  • Technorati
  • YahooMyWeb
  • DotNetKicks
  • DZone
  • TwitThis