# Silly JScript ?

**URL:** <https://boards.straightdope.com/t/silly-jscript/540178>\
**Category:** Factual Questions\
**Created:** [May 20, 2010, 8:47pm UTC](https://boards.straightdope.com/t/silly-jscript/540178 "2010-05-20T20:47:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![enipla](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@enipla](https://boards.straightdope.com/u/enipla)\
**Post date:** [May 20, 2010, 8:47pm UTC](https://boards.straightdope.com/t/silly-jscript/540178/1 "2010-05-20T20:47:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![friedo](https://avatars.discourse-cdn.com/v4/letter/f/8edcca/32.png) [@friedo](https://boards.straightdope.com/u/friedo)\
**Post date:** [May 20, 2010, 9:07pm UTC](https://boards.straightdope.com/t/silly-jscript/540178/2 "2010-05-20T21:07:42Z")

</div>

To update the contents of a DOM node, you’ll want to use the innerHTML property:

```auto

var L1 = document.getElementById( 'Label1' );
L1.innerHTML = 'TEST';

```

---

<div class="post-metadata">

**Author:** ![enipla](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@enipla](https://boards.straightdope.com/u/enipla)\
**Post date:** [May 20, 2010, 9:25pm UTC](https://boards.straightdope.com/t/silly-jscript/540178/3 "2010-05-20T21:25:03Z")

</div>

> [@friedo](#):
>
> To update the contents of a DOM node, you’ll want to use the innerHTML property:
> 
> ```auto
> 
> 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?

---

<div class="post-metadata">

**Author:** ![friedo](https://avatars.discourse-cdn.com/v4/letter/f/8edcca/32.png) [@friedo](https://boards.straightdope.com/u/friedo)\
**Post date:** [May 20, 2010, 9:29pm UTC](https://boards.straightdope.com/t/silly-jscript/540178/4 "2010-05-20T21:29:35Z")

</div>

Oh, I thought this was client-side Javascript.

I don’t know anything about ASP, sorry.

---

<div class="post-metadata">

**Author:** ![ZipperJJ](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/zipperjj/32/211_2.png) [@ZipperJJ](https://boards.straightdope.com/u/ZipperJJ)\
**Post date:** [May 20, 2010, 11:26pm UTC](https://boards.straightdope.com/t/silly-jscript/540178/5 "2010-05-20T23:26:49Z")

</div>

It’s [ASP.NET](http://ASP.NET) I assume, right?

You want to use L1 = getElementById(‘\<%=Label1.ClientID%\>’);

If you notice, when you execute a page, [ASP.NET](http://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.

---

<div class="post-metadata">

**Author:** ![enipla](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@enipla](https://boards.straightdope.com/u/enipla)\
**Post date:** [May 21, 2010, 8:47pm UTC](https://boards.straightdope.com/t/silly-jscript/540178/6 "2010-05-21T20:47:47Z")

</div>

> [@ZipperJJ](#):
>
> It’s [ASP.NET](http://ASP.NET) I assume, right?
> 
> You want to use L1 = getElementById(‘\<%=Label1.ClientID%\>’);
> 
> If you notice, when you execute a page, [ASP.NET](http://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.
