View Full Version : how do people debug vague javascript errors (Line 1, Char 5, Error: Syntax error)

09-29-2003, 05:43 PM
Appologies for the vague title but I wasn't sure what to really put there. IE gave me this wonderful error message when I clicked on an element with an onclick...

Line: 1
Char: 5
Error: Syntax error
code: 0
URL: ...blah... (a struts action url)...

of course line 1 is the <html> tag line so that's not where the error really is. The wierd thing is that the function that is suppose to occur when one clicks on the element actually works! so what the heck is the popup error box trying to tell me?????

09-29-2003, 05:46 PM
I try running it in the Mozilla or Netscape 7 browsers as their JavaScript consoles give better messages.

09-29-2003, 05:50 PM
I used to do that too. Unfortunately, my web application is embedded in another application which wont display on netscape.
It uses an old version of DynAPI, which doesn't work well on NS7, since it was really written with NS4 in mind.

09-29-2003, 06:58 PM
Yeah, the error messages in IE suck. However, if you think that this error means nothing, you could supress errors like this:

<script type="text/javascript">
window.onerror = function() { return true; }

You could also use a try/catch block and handle the exception.

09-29-2003, 07:31 PM
The easiest thing to do it to insert alerts in the script, that tells you the content of any varaibable, their type etc. That way you can easily see where it must lie and what causes it.

09-29-2003, 08:25 PM
Well, that's part of my problem. Remember, the function completes and does what its suppose to. I did put debug output all throughout the function and everything seemed fine. Normally, when I get 'Syntax Error', nothing after that point even executes. I'm getting completion and all the values seem fine.

09-29-2003, 08:26 PM
Can we see your source code possibly?

09-29-2003, 09:10 PM
Why don't you try using the script debugger (http://www.microsoft.com/downloads/details.aspx?FamilyId=E606E71F-BA7F-471E-A57D-F2216D81EC3D&displaylang=en) for this?