By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,421 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

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

P: n/a
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">SomeLastNa me, 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

Jun 6 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a

dnaumow...@gmail.com wrote:
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[i].htmlFor == checkboxClientID)
return labels[i].innerHTML;
}
return null;
}
Regards, Mykola
http://marss.co.ua

Jun 6 '07 #2

P: n/a
On Jun 6, 6:40 am, dnaumow...@gmail.com wrote:
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

Jun 6 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.