Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Asp.Net Programming

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


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

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

-----------------------------------------------Reply-----------------------------------------------
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

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc