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
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,960
    Thanks
    120
    Thanked 76 Times in 76 Posts

    meaning of var, IE

    This prbl. appears only in IE:

    Code:
    l2 = obj.parentNode.getElementsByTagName("select")[0].value;
    --> object does not support this property or method

    Code:
    var l2 = obj.parentNode.getElementsByTagName("select")[0].value;
    --> OK

    explanation needed.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,193
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    You probably have some tag on your page with that name or id.

    That is, maybe <input name="l2"> or <td id="l2">.

    IE *automatically* exposes such names and id's as global (page scope) variables.

    By prefixing your name with var, you are forcing IE to *not* use the default name/id mapping.

    Simple as that. Been discussed here many times, mostly by Philip.
    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.

  • Users who have thanked Old Pedant for this post:

    BubikolRamios (11-16-2010)

  • #3
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,960
    Thanks
    120
    Thanked 76 Times in 76 Posts
    jp, that is it, thanks.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    As an aside, I would always avoid variable names such as l2 as it is too easily confused with number 12.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,193
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    Yeah, I try to avoid variable names that start with lower case L and upper case i and o just for that reason. Even in my Java and C++ code. Willing to live with lower case L internally in variable names, esp. if the name is meaningful and the letter's use is obvious.
    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.


  •  

    Posting Permissions

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