Results 1 to 7 of 7

Thread: DIV show/hide

  1. #1
    Join Date
    Jul 2006
    Posts
    64
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Default DIV show/hide

    Hi, i'm looking for a piece of coding that will allow me to have two images (male and female image) and when a user click Male... below it will appear Male input information and if the Female image is clicked female input information is shown. example below. if i click image 1 the form info for image1 appears if i decide to click image 2 then image1 info hides and image2 info appears.


    Image 1 - Image 2

    ----------border-------------
    Information appears below

    You've selected Image 1
    user: name
    pass: 1234

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    ...something like this:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <style type="text/css">
    html,body {
        padding:0;
        height:100%;
     }
    #change
    {
    margin:10px auto auto 0;border:1px solid #000; background:#efefff; width:200px;
    text-align:center;
    height:100px;
    }
    </style>
    <script type="text/javascript">
    function male()
    {
    document.getElementById("change").innerHTML = "This is the male form<form name=\"form1\" method=\"POST\"><input type=\"text\"><br/><input type=\"submit\" value=\"Male\"><br/>"
    }
    function female()
    {
    document.getElementById("change").innerHTML = "This is the female form<form name=\"form1\" method=\"POST\"><input type=\"text\"><input type=\"submit\" value=\"Female\"><br/>"
    }
    </script>
    </head>
    <body>
    <a href="#"><img src="male.jpg" onClick="male()" border="0"></a>
    <a href="#"><img src="female.jpg" onClick="female()" border="0"></a>
    <div id="change">
    This area will show the forms selected
    </div>
    </body>
    </html>
    See if it helps
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  3. #3
    Join Date
    Jul 2006
    Posts
    64
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Default

    perfect example, thanks so much

  4. #4
    Join Date
    Jul 2006
    Posts
    64
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Default

    question, is there a way to put the innerhtml code load from a div? because my forms are pretty long and it would take a while to get everything formated to work within the javascript. it seems to work perfect for small code snipets.

  5. #5
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    We could change the code,..we'll use the display property of CSS instead of innerHTML. See this code:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <style type="text/css">
    html,body {
        padding:0;
        height:100%;
     }
    #change
    {
    margin:10px auto auto 0;border:1px solid #000; background:#efefff; width:200px;
    text-align:center;
    height:100px;
    }
    #male,#female{
    margin:1px auto;
    background:#efefff;
    width:200px;
    padding:5px;
    height:100px;
    text-align:center;
    }
    </style>
    <script type="text/javascript">
    window.onload = function ()
    {
    document.getElementById("male").style.display = 'none';
    document.getElementById("female").style.display = 'none';
    }
    function male()
    {
    document.getElementById("male").style.display = '';
    document.getElementById("female").style.display = 'none';
    }
    function female()
    {
    document.getElementById("female").style.display = '';
    document.getElementById("male").style.display = 'none';
    }
    </script>
    </head>
    <body>
    <a href="#"><img src="male.jpg" onClick="male(); return false" border="0"></a>
    <a href="#"><img src="female.jpg" onClick="female(); return false" border="0"></a>
    <div id="male">
    This is the male form
    <form name="form1" method="POST"><input type="text"><br/><input type="submit" value="Male"><br/>
    </div>
    <div id="female">
    This is the female form<form name="form1" method="POST"><input type="text"><input type="submit" value="Female"><br/>
    </div>
    </body>
    </html>
    See if it helps
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  6. #6
    Join Date
    Jul 2006
    Posts
    64
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Default

    thank that worked perfectly

  7. #7
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    You're welcome!..Glad I could help
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

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
  •