Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Apr 2010
    Posts
    163
    Thanks
    3
    Thanked 25 Times in 25 Posts

    IE compatibility issue

    EDIT: i think the problem was i had an html element named 'comment' so IE was getting confused when i made a js variable 'comment'
    (don't use IE it is the worst browser)


    i am in the process of debugging a website, it works wel in Google Chrome and firefox but not in IE
    i am putting all the relevant code below.
    this is in the head tag, and is the only JavaScript executed when the debugger show the error
    Code:
    function first_run(){
    answer_state=document.getElementById('state');//set node for 'show_answer' function
    answer_ab=document.getElementById('ab');//set node for 'show_answer' function
    answer_capitol=document.getElementById('capitol');//set node for 'show_answer' function
    answer_next=document.getElementById('next');
    comment=document.getElementById('comment')//line marked with error
    ui=document.getElementById('UI');//sets 'ui' to form location
    score_right=document.getElementById('right');//returns null
    score_wrong=document.getElementById('wrong');
    score_right=score_wrong.previousElementSibling//score_right work around
    score_show_ans=document.getElementById('show_ans');
    runs above code on page load
    Code:
    <body onkeydown="if (event.keyCode == 13){check()}" onload="first_run()">
    in body tag, node that erred line refers to.
    Code:
    <div id=comment>
    </div>
    the error message in IE's developer tools debugger is "Object doesn't support this property or method" States javascript.html, line 395 character 1"

    i've done all of my coding in Chrome and have no expirence in IE's syntax, any ideas what the problem is?
    Last edited by gizmo1650; 04-14-2010 at 01:36 AM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,171
    Thanks
    75
    Thanked 4,339 Times in 4,305 Posts
    I think you have the wrong line.

    That message would occur because you tried to do something like
    Code:
       comment.framitz = 17;
    or
       comment.zam();
    MSIE's line numbers are often off by 1 or 2 in the error messages.

    Can you show us the next 5 or 10 lines, right after the ones you showed?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Regular Coder
    Join Date
    Apr 2010
    Posts
    163
    Thanks
    3
    Thanked 25 Times in 25 Posts
    i added a few lines to the code
    using the javascript console shows everything up to and including comment=document.getElementById('comment') works (putting in the variable name doesn't return undefined) but the following few lines, putting in the variable name returns undefined
    Last edited by gizmo1650; 04-13-2010 at 11:34 PM.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,171
    Thanks
    75
    Thanked 4,339 Times in 4,305 Posts
    Almost surely this line:
    Code:
    score_right=score_wrong.previousElementSibling//score_right work around
    If you look here:
    http://msdn.microsoft.com/en-us/libr...(v=VS.85).aspx
    and scan the properties, you will see previousSibling but no mention of previousElementSibling.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Regular Coder
    Join Date
    Apr 2010
    Posts
    163
    Thanks
    3
    Thanked 25 Times in 25 Posts
    changing to Previous sibling didn't help,
    also this time i noticed when i ran the debugger thare was a balloon that popped up for a few seconds over the comment= line that said "breaking on JS runtime error-Object doesn't support this property or method" so i don't think it is even looking at the code beyond this

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,171
    Thanks
    75
    Thanked 4,339 Times in 4,305 Posts
    I'm convinced it is *not* that line.

    But convince yourself.

    Put an alert() just after the comment= line.

    Then put one just before and just after the previousElementSibling line. Betcha that narrows it down.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Regular Coder
    Join Date
    Apr 2010
    Posts
    163
    Thanks
    3
    Thanked 25 Times in 25 Posts
    solved.
    I ided the div element to html_comment, and that solved the problem. Unfortuantly now i am fining alot of other problems (including previusElementSibling)

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,171
    Thanks
    75
    Thanked 4,339 Times in 4,305 Posts
    Bizarro. I'd have to guess that you also had a form field with that name, right? And so MSIE tries to find the form field as well as the div. And so getElementById() is trying to process two objects by what it thinks is the same id??? Still...why *that* error message. Joy and light.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #9
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Note that in Internet Explorer, names and IDs are global variables and thus you should NEVER use a global variable or function name which is the same as an HTML element name or ID.

    comment=document.getElementById('comment')

    You should also avoid giving names or id's to your variables/functions/arguments/forms words which are JavaScript methods/properties/attributes such as 'name' or 'id' or 'value' or 'text' or 'checked' or 'submit' or 'replace' or 'button' or 'radio' or 'parseInt'.

    And of course you may not give a variable a name which is a Javascript keyword or event such as alert, case, char, false, int, onload, return, this, void, and so on.

    Also avoid words such as description, author, keyword and generator which may appear in META tags.

    There is no point in saying "Don't use IE". IE has 62% of the market and any useable web page must be IE compatible.
    Last edited by Philip M; 04-14-2010 at 09:11 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •