Results 1 to 6 of 6

Thread: Show and Hide in php

  1. #1
    Join Date
    Feb 2009
    Posts
    27
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Arrow Show and Hide in php

    Hi to all,

    please tell me any easy php code,

    To 'show' and 'hide' a new form file (may be called as "form1.php")
    on same current page
    by click on radio buttons ?


    Any suggession will be appreciated,


    Thanks and Regards

  2. #2
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    If you want a radio button to control what is displayed on a page without reloading the page, you'll need to use javascript. If I misunderstood what you are asking about, post again.

  3. The Following User Says Thank You to JasonDFR For This Useful Post:

    MSK7 (02-04-2009)

  4. #3
    Join Date
    Feb 2009
    Posts
    27
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default show and hide form

    Please suggest,

    How javascript codings can help me in easy way, To "show" and "hide" any other new form file (may be called as "form1.php") on my other current page,
    on click of radiobuttons.


    Thanks & Regards.

  5. #4
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    I'm not that great with javascript. You should post your question in the javascript section.

    Good Luck!

  6. #5
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    It should be in the JavaScript section yes, but here is a stab at it anyway:

    HTML: (remember you need to save this as .php as well)

    Code:
    <html>
    <head>
    <title>Hide Form</title>
    <script type="text/javascript">
    function showForm(){
    var form = document.getElementById("hiddenform");
    form.style.display='block'
    }
    
    
    </script>
    <style>
    #hiddenform{
    display:none;
    }
    </style>
    </head>
    <body>
    Bla bla this text is visible and all my content is here.
    
    <form>
    <input type="radio" onclick="showForm();" name="show" value="On">On<br />
    <input type="radio" name="show" value="Off">Off
    </form>
    
    <div id="hiddenform">
    <?php include("form1.php"); ?>
    </div>
    
    
    </body>
    </html>
    May not be the best way to do it, but gets the job done.

    Good Luck!

  7. #6
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,626
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Some refinements to Schmoopy's code

    Code:
    <html>
        <head>
            <title>Hide Form</title>
            <script type="text/javascript">
                function showForm(flag) {
    		document.getElementById('hiddenform').style.display = flag === 1 ? 'block' : 'none';               
                }
            </script>
            <style type="text/css">
                #hiddenform {display: none}
            </style>
        </head>
        <body>
            Bla bla this text is visible and all my content is here.
            <form>
                <input type="radio" onclick="showForm(1);" name="show" value="On">On
                <br/>
                <input type="radio" name="show" value="Off" onclick="showForm(0);">Off
            </form>
            <div id="hiddenform">
                <?php include("form1.php"); ?>
            </div>
        </body>
    </html>
    There is no need for the 'Off' radio button unless we need to hide the form, I have added it here. Additionally some misc changes in JS side. As he mentioned this approach will work under normal circumstances.

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
  •