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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Show/Hide DIV probelm

    I would like to change some features of this script:
    The checkbox is the one who shows and hides the div.

    The div has to be closed when the page loads.
    The row of the checkbox (bgcolor="#808080") has to change color when it shows the content of DIV (becomes #efefef)
    Has to work in Explorer and FF
    Can anyone help pls

    <script type="text/javascript">
    function ShowHide(obj, visibility) {
    if(document.getElementById){
    divs = document.getElementsByTagName("div");
    divs[obj].style.visibility = visibility;
    }
    }
    </script>

    <table>

    <tr>
    <td bgcolor="#808080"><input type="checkbox" value="" onclick="ShowHide('lyr1','visible')">
    <a href="#" onclick="ShowHide('lyr1','hidden')">hide</a><br/></td>
    </tr>
    <div id="lyr1">lyr1</div>
    </table>

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Provo, UT
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Here is how I would do it.

    Code:
    <script type="text/javascript">
    function ShowHide(show, obj ) {
    
    if(show){
    document.getElementById(obj).style.display = 'block'; //or inline whatever
    }else{
    document.getElementById(obj).style.display = 'none';
    }
    document.getElementById('checkBoxCell').style.backgroundColor = "#efefef";
    }
    </script>
    
    <table>
    
    <tr>
    <td bgcolor="#808080" id="checkBoxCell"><input type="checkbox" id="checky"  onclick="ShowHide(this.checked, 'lyr1');"><label for="checky">hide</label><br/></td>
    </tr>
    <div id="lyr1" style="display:none;">lyr1</div>
    </table>
    Last edited by MikoLone; 05-09-2006 at 12:03 AM.
    I try to convince 'em that I am computer geek, but I just can't do it. Why? Oh why?


  •  

    Posting Permissions

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