WEBDOOD.COM

Tag: expression

The dreaded “Line 0, Object Expected” Javascript error

by webdood on Sep.05, 2008, under IE-Specific, Javascript, Software Development

One of my favorite mechanisms to do IE-specific CSS is to use the so-called dynamic properties available to IE5+ browsers. Firefox and Opera ignore these tags, so if, for instance you need a div of id “foo” to be 110 pixels in IE and 100 pixels in all other browsers, you would just do this:

#foo {
  width: 100px;
  width: expression(’110px’);
}

Of course, there are easier ways of doing this in IE if you just need a fixed value to appear, using the so-called IE CSS hacks like the star harck *width:100px or _width:100px; will only be interpreted by Internet Explorer, but when you need a truly dynamic property that is based on changing conditions, using “expression” is a valid tactic.

I began to encounter a strange Line 0. Object Required Javascript bug and spent the better part of a day trying to track down the cause. The bug was so severe that, when hit, it required me to close IE using Task Manager. I could not figure this one out and finally resorted to reconstructing the entire page, line-by-line until I found the problem.

I finally determined it occurred only when I added a <textarea> tag to the page. My current project is a Ruby on Rails app, which necessarily indludes the Prototype Library, so I initially wrote off this weirdity to the vagaries of Prototype and its many tens of thousands of lines of code.

In this context, an input type=text tag would do fine, so I switched to that and moved on.

Quite by accident, I stumbled across this section in my CSS file:

.WordBubble textarea {
  overflow:hidden;
  border:solid 1px lightBlue;
  height:30px;
  width:expression(document.getElementById(‘WordBubble’).offsetWidth-66);
}

And WHALA, the answer!

Thinking to reuse a WordBalloon construct I had developed, I had modified this CSS to play off of .WordBubble the className vs the original #WordBubble the ID. Therefore, when I used the original:

<div id=”WordBubble” class=”WordBubble”>
<textarea>
</div>

things worked as expected.

However, when using:

<div id=”AnotherWordBubble” class=”WordBubble”>
<textarea>
</div>

The CSS, when evaluating the dynamic property, could not find “WordBubble” as it did not exist as an ID (see it’s now a className).

Although I realize this posting is somewhat confusing (I barely understand it myself), what I am trying to say is “When you get a Line 0, Object Expected” Javascript error and can’t figure out where it comes from, check your CSS for Expression use.

Shannon

Leave a Comment :, , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...

  • A List Apart
  • Dive into HTML5
  • Javascript: The Good Parts
  • QuirksMode.org