#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    knee deep in sh*t
    Posts
    254
    Rep Power
    64

    javascript to set visible/hidden in ie


    Hi,

    I am goofing around with some dhtml in which I have several layers, one which contains an image. When the image is clicked, I would like the "main" div which contains the contents to be hidden from view. Very similar to the way a windows' window works.

    Here is my script:

    <script language=javascript>
    function closeObject(someID)
    {
    document.getElementByID(someID)style.visibility = 'hidden';
    }
    </script>
    </head>
    <body>

    <div class=box id=box>
    <div class=menu id=menu>
    <a href=# "onClick=closeObject('box'); return false;"><img src=buttons.gif border=0 height=14></a>
    </div>
    <div class=body id=body>
    In this week's &quot;Wally report,&quot; I've decided to let my hair grow long in the back.
    </div>
    </div>

    </body>
    </html>

    I don't receive any errors when I run the script, but the div is not hidden from view!?

    Thank you for your time and help,
    oach
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Oct 2001
    Location
    New Zealand
    Posts
    1,774
    Rep Power
    24
    <a href=# "onClick=closeObject('box'); return false;">

    should be:

    <a href="javascript: closeObject('box')">

    and:

    <script language=javascript>
    function closeObject(someID)
    {
    document.getElementByID(someID)style.visibility = 'hidden';
    }
    </script>

    should be:

    <script type="text/javascript">
    function closeObject(someID)
    {
    var thisObj = eval("document.getElementByID('" + someID + "')style")

    thisObj.visibility = "hidden";
    }
    </script>
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    knee deep in sh*t
    Posts
    254
    Rep Power
    64
    binky,

    I implemented your changes, with a few additions. I think you forgot to place a . and ; in the following line:

    var thisObj = eval("document.getElementByID('" + someID + "')style")

    so I added to get:

    var thisObj = eval("document.getElementByID('" + someID + "').style");

    But, when I run the program it still doesn't work and I now get a javascript error which points to the above line stating:

    "Object doesn't support this object or method."

    Any ideas, I am listing the code as it is now:

    <script type="text/javascript">
    function closeObject(someID)
    {
    var thisObj = eval("document.getElementByID('" + someID + "').style");
    thisObj.visibility = "hidden";
    }
    </script>
    </head>
    <body>

    <div class=box id=box>
    <div class=menu id=menu>
    <a href="javascript:closeObject('box')"><img src=buttons.gif border=0 height=14></a>
    </div>
    <div class=body id=body>
    In this week's &quot;Wally report,&quot; I've decided to let my hair grow long in the back.
    </div>
    </div>

    Thank you,
    oach
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Posts
    1,882
    Rep Power
    19
    ID needs to be Id
    getElementById

    Code:
    <html>
    <head>
    <script> 
    function closeObject(someID) 
    { 
    document.getElementById(someID).style.visibility = 'hidden'; 
    } 
    </script>
    </head> 
    <body> 
    <div id="box">
    <a href="javascript:closeObject('box')"><img src="buttons.gif" border="0" height="14"></a>
    </div>
    <div id="body"> 
    In this week's "Wally report," I've decided to let my hair grow long in the back. 
    </div>
    </body> 
    </html>
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    knee deep in sh*t
    Posts
    254
    Rep Power
    64
    Hard to believe, but, that was all!!!!!!!

    Thank you for your help,
    oach

IMN logo majestic logo threadwatch logo seochat tools logo