Nope; a check box doesn't have a text property in HTML.
To see how .NET does it, create a brand new web page, add a CheckBox control to the page, set its Text property and then request the page in the browser. The final HTML of the page shows you something like this:
<input id="CheckBox1" type="checkbox" name="CheckBox1" />
<label for="CheckBox1">My Old Text</label>
As you can see, it's quite difficult to target the text, as it's stored in a <label /> element without an explicit ID. I think the following would work around this, and find the right <label />:
Code:
var allLabels = document.getElementsByTagName("label");
for (var i = 0; i < allLabels.length; i++)
{
if (allLabels[i].htmlFor == "CheckBox1")
{
allLabels[i].innerText = 'My New Text';
}
}
Since this is very fragile code, and really depends on a fixed naming scheme, you may be better off leaving the Text property of the CheckBox control empty, and manually create a <label /> for it.
Hope this helps,
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of
Beginning ASP.NET 3.5 : in C# and VB,
ASP.NET 2.0 Instant Results and
Dreamweaver MX 2004
Want to be my colleague? Then check out this post.