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 5 of 5
  1. #1
    wac
    wac is offline
    Regular Coder wac's Avatar
    Join Date
    Sep 2002
    Location
    Cary, North Carolina, USA
    Posts
    359
    Thanks
    2
    Thanked 0 Times in 0 Posts

    javascript variables and element ID in IE6

    I've noticed that Internet Explorer doesn't like javascript variable names which are the same as an elements ID or 'name'. Have people bumped into this issue (or is it just me :-) )?

    I've pulled out numerous hairs chasing down bugs related to this issue. Once I changed the variable name and reverted back to the original code things worked fine.

    Just wondering if anyone else has seen this (miserable, now bald, people love company).

    Wayne Christian
    wac@genesyslab.com
    Wayne Christian

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    IE exposes document.all on top of the window object as well.

    document.all.bla == document.all('bla') == document.all['bla'] == window.bla == bla;

    Really bad decision on their part, among others.

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's not the best no; it's also dangerous in the sense that iterating through the all collection is very inefficient; yet the ease with which objects are exposed gives you false impression that it's something you might want to use.

    But are you talking about things like

    var something = document.getElementById("something") ?


    Which presumably you want to do to make it easier to remember what things are? In which case I have two suggestions. The first is to take advantage of javascript's case sensitivity and use that to differentiate in a way that shouldn't be problematic. eg

    var someThing = document.getElementById("something")


    The second suggestion - comment a lot. Preferably every line.

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ditto on what brothercake said. For object IDs I try to use underscores, and uppercasing for 2-word variable names

    <div id="some_thing"></div>

    var someThing = document.getElementById('some_thing');

    However, whenever possible, I try to encapsulate my code in functions that use generic variable names...like o, i, node, arr, stuff like that....
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Round Rock, Texas
    Posts
    443
    Thanks
    0
    Thanked 0 Times in 0 Posts

    This should help some

    http://www.webreference.com/js/

    The above link has some decent tutorials on the DOM - and more to the point a couple of "columns" on the differences between IE and NN.

    good luck!

    P.S. if/when you figure it all out let me know!


  •  

    Posting Permissions

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