Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Label text

Status
Not open for further replies.

dvannoy

MIS
May 4, 2001
2,765
US
I am creating a web app in asp.net...I am using a datagrid with checkboxes. when the users click on the checkbox I want the text of a label to change. how can this be done using java script?

any help would be appreciated

Thanks

 
I think that the checkboxes are typically supposed to reside inside the label tags, but this still works:
Code:
<html>
<head>

<script type="text/javascript">

function changeLabel(bool) {
   document.getElementById("myLabel").innerHTML = (bool) ? "Checked" : "Not Checked";
}

</script>
</head>
<body>
<input type="checkbox" id="myCheckbox" onclick="changeLabel(this.checked)">
<label for="myCheckbox" id="myLabel">Not Checked</label>
</body>
</html>

-kaht

How much you wanna make a bet I can throw a football over them mountains?
sheepico.jpg
 
I don't think that's going to work since the label is in the grid as well. so it would have to reference

e.items.findcontrols

I am really stuck on this

 
Maybe ask over in the asp.net forum... kaht has given a good working solution but from your reply I think you need something that is more "asp.net - centric".

Speaking for myself, I have no understanding of what you mean by "grid" - I'm assuming it's a jargon word used in the programming environment or work that you are involved with.

The word has no relevance to me and I just can't place it in a meaningful context for this problem. I initially assumed the same with your use of the word "label" - because in the HTML world there is a tag called a label and it is used with form elements.

Anyway, I just reckon you will get a much more meaningful answer to your question over in the asp.net forum [smile]

Cheers,
Jeff



[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]

What is Javascript? faq216-6094
 
This works if the text is immediately following the checkbox. Also, this might only work in IE ...

Code:
<script>
	function changeLabel(ele) {
		ele.nextSibling.nodeValue = ele.checked?'on':'off';
	}
</script>
<input type='checkbox' id='chkTest' onclick='changeLabel(this)'>off

Chaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top