views:

297

answers:

5

OK,

Here is my problem, I have a master page with a HEAD section that contains my JS includes. I have one JS include

<script src="Includes/js/browser.js" language="javascript" type="text/javascript"></script>

In my page i consume it like this:

<body>
<form id="form1" runat="server">
<div>
....
<script type="text/javascript">registerBookmarkButton();</script>
....
</div>
</form>
</body>

And i get this error:

Line: 216
Error: Object expected

Please tell me i just missed something and it's a stupid mistake

+2  A: 

As you wish.

You just missed something and it's a stupid mistake.

:)

That being said, I'd try to find out which file it is that has the faulty line 216. Perhaps it's the browser.js file? Other possibilities include:

  • You messed up the URL and the file isn't loaded;
  • The function depends on the DOM to be completely loaded, but it's called before the relevant elements are created (most JS should be done after the onload event under normal circumstances).

Vilx-
+2  A: 

If you can use Firefox, I would highly recommend installing and enabling the Firebug addon.

Otherwise, see some of the following for tools that might help:

Mark Renouf
A: 

The "Object expected" error occurs when the browser's script engine was expecting to find an object, but was unable to do so. This usually occurs when you try to make a function call, but the function itself is unavailable to the script engine, presumably because you mistyped the function name when calling it.

To successfully debug this error, you must first determine the instruction at the line number reported in the error. This cannot be done by browsing through all the source files, unless you have some psychic debugging powers. It is recommended that the exception be caught inside a JavaScript debugger. If you are debugging this under MS IE, you might want to install Microsoft Script Engine which can be installed with MS Office, or the poor man's Microsoft Script Debugger. For Firefox, there are the excellent Firebug and Venkman extensions. Jonathan Boutelle's blog post on debugging JavaScript in IE seems like a must read.

Vineet Reynolds
+1  A: 
  1. Try running your code through JSLint.
  2. Add alert() calls here and there to narrow down the error to a particular location.
Ates Goral
@Ates, I love how it's 2010 and were still using 'alert()' statements to debug javascript
Chris
Of course, one should use the Firebug console whenever possible, but `alert` still seems to be the most "portable" way.
Ates Goral