I have a label with ID = Label1 in a form document.
Shouldn’t this code change the text in the label to ‘TEST’?
<script type=“text/javascript”>
L1 = document.getElementById("Label1");
L1.Text = "TEST";
</script>
Thanks
I have a label with ID = Label1 in a form document.
Shouldn’t this code change the text in the label to ‘TEST’?
<script type=“text/javascript”>
L1 = document.getElementById("Label1");
L1.Text = "TEST";
</script>
Thanks
To update the contents of a DOM node, you’ll want to use the innerHTML property:
var L1 = document.getElementById( 'Label1' );
L1.innerHTML = 'TEST';
hmmm… It’s an ASP label.
With your code, I get the error - Microsoft JScript runtime error: ‘L1’ is null or not an object
Can I not update ASP?
Oh, I thought this was client-side Javascript.
I don’t know anything about ASP, sorry.
It’s ASP.NET I assume, right?
You want to use L1 = getElementById(‘<%=Label1.ClientID%>’);
If you notice, when you execute a page, ASP.NET changes the IDs of all of your ASP elements to crazy other IDs like ctrl$001Label1. That’s the ID you need to address it by when running Javascript. That’s called the ClientID.
Just want to say thanks. I was not able to go to work today and try it though, my Wife has car troubles.