Internet Explorer Javascript Errors

July 21st, 2006

Evolution and Geneone have been plagued by some Javascript errors in Internet Explorer over the last few weeks. To be honest, the number of people who play Evolution or visit my blog using IE are so low that no one has actually bothered complaining.

These errors included Object expected and "Expected identifier, string or number". I’ve never tried to actually fix these errors before because IE’s script debugging really really sucks. 

Windows Scripting Debugger can be a useful tool for debugging Javascript but be warned that it is very very unstable and severely affects the stability of your computer.

Expected identifier, string or number

This was an annoying little bug caused in a class because of a comma at the end. In Javascript you have lists like:

var list = { opacity: 0.5, height: 0.5} 

Similar syntax is used to group functions:

var MyFuncs = {bleh : function() {},bleh2 : function() {},} 

The above code should work fine in real web browsers such as Firefox. IE will give a screwed up error such as "Expected identifier, string or number". Just remove the comma after the last function and the error be gone.

Object Expected

If you document.getElementsById(’nonexistantitem’) in Firefox and try to retrieve an attribute such as previousSibling, Firefox won’t complain. IE will. This was causing issues as I had a little bit of Javascript which searched for the "Entry Title" box above the "Message" box in the Object Creation forms. On pages where the Entry Title field weren’t shown, IE would freak out as the previousSibling would return False.

I should thank neonDragon for his assistance in resolving these issues

Related Posts

  1. It’s rewarding being a blogger
  2. FireBug
  3. Gene_Template
  4. Annoying things about PHP
  5. Software Updates

26 Responses to “Internet Explorer Javascript Errors”

  1. Peter Goodmanon 22 Jul 2006 at 6:50 am

    The actual syntax is:

     var list = {

     a: function() {

    },

    b: "some value"

    }; 

     

    (note the semicolon at the end)

     

    Also, it’s good practice to actually error check your code.. e.g.:

     

    var elm = document.getElementById(’whatev’);

     

    if(elm) { … } 

  2. Peter Goodmanon 22 Jul 2006 at 6:52 am

     P.S.You should check out JSLint, it will help you debug your javascript.

     

  3. Khloon 22 Jul 2006 at 12:14 pm

    Ah cool, thanks for the information. The problem was I was trying to look for the element which came 2 places before a specific element. So I had code like:

    document.getElementById(’magnets’).previousSibling.previousSibling.previousSibling.previousSibling.

    It was possible that .previousSibling.previousSibling didn’t exist so I had to check for that before calling previousSibling again twice.

    Thanks for the info about JSLint, should come in really handy! 

  4. Chris Iuferon 23 Sep 2006 at 12:28 am

    awesome. saved my butt when all was lost… these IE error messages just never help.

  5. Chrison 06 Nov 2006 at 5:18 pm

    Thank you for posting this.  I have a JSON object that is >60K and it would have taken me forever to find that I have an extra comma at the end.  You just saved me a ton of time.

  6. Gerald Deutschon 20 Feb 2007 at 12:32 am

    You went probably way too far - too much bother to fix that as interestingly enough its mostly M$ own sites that also trigger that error message (my favourite being their beta site). Don’t know, dear Microsofties but you happen to test your own web pages with firefox? It WOULD be clever to do so, I’d grant you that

  7. David Conradon 28 Feb 2007 at 8:29 pm

    Thank you, thank you, thank you! I just spent half an hour or more wrestling with the "Expected identifier, string or number" error!

  8. Yuriyon 18 Jul 2007 at 12:26 am

    thanks for this article, helped me with my problem!

  9. Slavaon 17 Aug 2007 at 8:26 am

    Thanks very much for the article.

    I almost crushed my head figuring out what is wrong with my code. The most nasty thing is that Explorer has allowed code to be executed partly, which really disturbs and hides the problem.

  10. Andyon 28 Aug 2007 at 3:56 pm

    Know this was prob an old post but I just wanted to thank you for this  stumbled  upon your blog via google. Thanks a mill  spent way too long trying to figure that one out! IHATE IE!!!

     But thanks :)

  11. Remon 10 Oct 2007 at 3:01 am

    Thank you! Your article helped me fix an issue developing some Javascript in IE.

  12. Saikrishnaon 25 Oct 2007 at 8:17 am

    Thanks a million for this post. You are a lifesaver !

  13. Yeeon 25 Oct 2007 at 10:37 am

    Thank you, thank you.
    You saved me plenty of time and hair-pulling.
    Bloody little comma, who would’ve known.
    And the useless error message doesn’t help.

    Thanks again.

  14. Hughon 28 Dec 2007 at 3:01 am

    I’d like to add another Thank You!  Been fighting a stupid IE error for hours, thanks to this page I tracked it down to a trailing comma in an AJAX data array, about a thousand lines away from where IE was bitching about, in a totally different function!

       — hugh
     

  15. Cars For Saleon 24 Jan 2008 at 11:57 pm

    I am using similar kind of editor as this is used for comments typing. I am adding this javascript editor in my website. The problem is if I put some comma like this ( ‘ ) and save in database. Again when i click to edit these text then it won’t show the textarea with value getting from database. Without comma ‘ it works ok.

     

    Is there any solution or fixes in javascript. thanks 

  16. Zackon 28 Feb 2008 at 10:36 pm

    Ah, I love the internet. You just solved a very perplexing problem I was having in IE. Argh, ye blasted comma! Anyway, cheers –

  17. [...] down the problem causing obscure “Expected identifier, string or number” errors. It turns out that it was caused by having a comma after the last element of a list, e.g. 1 2 3 4 5 6 7 var list [...]

  18. Fadion 03 Apr 2008 at 6:10 am

    hi

    I just want to say thank you so much for the information

    i was fighting this bug for about 1 - 2 hours until i found the f***ing comma after searching at the almost the end of the function , now everything is work well

    thanks again

  19. Hodgeon 20 Apr 2008 at 1:57 pm

    2 bugs down… 369,532 to go… If only the rest of the world would use Firefox, eh?

  20. RQon 08 May 2008 at 8:46 am

    Gee, this posting just solved a problem I was having. I had no clue that this comma I accidently left at the end of an array would break IE. Thanks! :)

  21. [...] two years ago, I experienced an persistent error in my Javascript development in one of my scripts. It was the case of the “Expected [...]

  22. Naokoon 21 May 2008 at 1:49 pm

    OH Just Thank you so much for your post….
    You have saved me tons of time.

  23. sivaon 24 May 2008 at 3:40 am

    “Expected identifier, string or number” error comes if we have null has key in some object. E.g.: {null:”TEST”}

  24. Parag Desaion 04 Jun 2008 at 12:58 pm

    You can try using Other Alternate Browsers, if problem is really with your Internet Browser or the system.

  25. Yuraon 06 Jun 2008 at 4:03 pm

    I use http://www.goodbyeie6.org.ua/ and forgot about IE6. Plus my users downloads new browsers.

  26. Zackon 17 Jun 2008 at 5:03 am

    Thank you for posting this. I have spent way too many hours trying to get things to work in IEEEEEEEEE (sorry to scream). I think you hit the nail on the head when you talked about internet explore being hard to debug scripts, they are virtually impossible.

Trackback URI | Comments RSS

Leave a Reply