how to have javascript access the text of a checkbox created by .Net 2.0

D

dnaumowicz

Hi,

I have a page done in ASP .NET 2.0 that uses an asp:CheckBox. .Net
renders the CheckBoxin the following manner:
<input id="_ctl0_Body__players__ctl0__player" type="checkbox"
name="_ctl0:Body:_players:_ctl0:_player" /><label
for="_ctl0_Body__players__ctl0__player">SomeLastName, SomeFirstName </
label>

How do I access the value of the label for that CheckBox using
javascript? There is no id, tag or anything else to tie it into
something that I can grab.

Any and all help is appreciated.

Thanks,

David
 
M

marss

There is no id, tag or anything else to tie it into
something that I can grab.

Hi,
Here is the "label" tag. It is not worse then any other tag.
You can get all elements of the "label" type and find among then an
element that refers to the given checkbox.
Example:

function getLabelValue(checkboxClientID)
{
var labels = document.getElementsByTagName("label");
for(var i=0; i<labels.length; i++)
{
if (labels.htmlFor == checkboxClientID)
return labels.innerHTML;
}
return null;
}
Regards, Mykola
http://marss.co.ua
 
G

Guest

There is no id, tag or anything else to tie it into
something that I can grab.

All server controls have an ID.

The Client ID of your CheckBox is _ctl0_Body__players__ctl0__player

To refer to that control from the client script you can use the
ClientID property,

for example

var chk = document.getElementById('<%=player.ClientID%>');
// where 'player' is the name of your CheckBox control
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top