homepage Welcome to WebmasterWorld Guest from 54.242.126.9
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
JavaScript error out of nowhere
IE fails, Firefox works, can't see a problem with the code
Purple Martin

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3110533 posted 4:36 am on Oct 6, 2006 (gmt 0)

IE is giving me a JavaScript error out of nowhere, Firefox is not giving any error.

The page has a bit of inline JavaScript, then links to a couple of external js files, then a bit more inline JavaScript where the error occurs.

The error message gives a line number that is in the middle of some HTML with no JavaScript at that part of the file, so the line number must be very wrong.

I couldn't see what was causing the error so I added lots of alerts to try and identify the line with the problem.

In the code sample below, the error occurs between the two alerts shown! I have double-checked that there are no strange characters in there.

...

<script type="text/javascript">
alert("OK CCC");
</script>

<script type="text/javascript">
alert("OK DDD");

...

 

daveVk

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3110533 posted 6:00 am on Oct 6, 2006 (gmt 0)

In firefox check javascript console for any warnings or error messages. Cant see problem with what you posted, perhaps larger snippet would help, apart from that, validate html and CSS maybe.

penders

WebmasterWorld Senior Member penders us a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



 
Msg#: 3110533 posted 10:04 am on Oct 6, 2006 (gmt 0)

The error message gives a line number that is in the middle of some HTML with no JavaScript at that part of the file, so the line number must be very wrong.

The line number that is reported could be in one of your external JS files - although IE always reports the URL of the main HTML page.

Rambo Tribble

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3110533 posted 12:43 pm on Oct 6, 2006 (gmt 0)

What does the error message say?

Purple Martin

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3110533 posted 11:47 pm on Oct 11, 2006 (gmt 0)

In firefox check javascript console for any warnings or error messages.

The console shows no errors in Firefox. alert("OK DDD") is executed successfully in Firefox. The error only occurs in IE.

Cant see problem with what you posted, perhaps larger snippet would help

I can't see a problem with it either! But that is where it fails: IE shows alert("OK CCC") and then gives an error message before it gets to alert("OK DDD")... the really strange thing is that there is no actual code in between them.

What does the error message say?

It says "Expected Identifier".

Rambo Tribble

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3110533 posted 12:26 am on Oct 12, 2006 (gmt 0)

Well, you may already know this, but here's the page MSDN has on that error: [msdn2.microsoft.com...]

What happens if you put a timeout after the first alert and before the second?

[edited by: Rambo_Tribble at 12:31 am (utc) on Oct. 12, 2006]

daveVk

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3110533 posted 1:00 am on Oct 12, 2006 (gmt 0)

Try changing alerts to defaultStatus = "Ok CCC"; etc and look at status line at time of error. There may be a timing issue with some other code executing between or during alerts.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved