views:

15

answers:

1

How to get a asp:radiobutton text in javascript?

I use this

RbDriver1.Text = dt.Rows[0].ItemArray[5].ToString(); 
RbDriver2.Text = dt.Rows[0].ItemArray[6].ToString() ;

and my javascript function is

function getDriverwireless() {
alert(document.getElementById("ctl00_ContentPlaceHolder1_RbDriver1"));
alert(document.getElementById("ctl00_ContentPlaceHolder1_RbDriver1").innerHTML);
}

innerHTML doesnt seems to take the text of my radiobutton...any suggestion

When i inspect throgh firebug i found this

<input type="radio" onclick="getDriverwireless();" value="RbDriver1" 
name="ctl00$ContentPlaceHolder1$drivername" 
id="ctl00_ContentPlaceHolder1_RbDriver1">
<label for="ctl00_ContentPlaceHolder1_RbDriver1">kamal,9566454564</label>

I want to get the value kamal,9566454564 in javascript...

+1  A: 

Try to avoid using client ids in your js.
Regarding your question, the RadioButton control renders that html that you can see in firebug. using your approach of clientids:

document.getElementById("ctl00_ContentPlaceHolder1_RbDriver1").nextSibling.innerHTML

Matias