SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2006
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why doesn't this work in IE?

    function disappear(){
    myField.style.display = 'none';
    }

    window.onload = function(){
    var myField = document.getElementById("myField");
    myField.style.display = 'none';
    }

    When the page loads, myField is visible. Obviously in the onload code, the line setting the style to none did not work. However, in a form I have...

    <button onclick="disappear();">WTF IS WRONG WITH IE</button>

    And that will make myField disappear. Two exact lines of code. Why doesn't the one in onload work? Nor does calling disappear() in window.onload work.

    Anyone know what's up with that in internet explorer? It works in firefox.

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is nothing wrong with that code, it works fine in IE, as you can see by this complete example:
    Code:
    <html>
    <head>
    <script type="text/javascript">
    window.onload = function(){
    var myField = document.getElementById("myField");
    myField.style.display = 'none';
    }
    </script>
    </head>
    <body>
    <div id="myField">THIS IS MYFIELD!!!</div>
    </body>
    </html>

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2006
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Would it make a difference if the div was inside a form, and inside some nested tables?

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not if everything was well formed no.

    I propose to you that the problem lies elsewhere (invalid html, overwriting the function, something else exploding before it gets to onload...)


Bookmarks

Posting Permissions

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