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 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2011
    Posts
    35
    Thanks
    18
    Thanked 1 Time in 1 Post

    show div when php variable $_GET is set and ....

    i'm trying to change hidden div's display to block if the certain conditions in php will be true. so what i have is:

    Code:
    <head>
    <link rel="stylesheet" type="text/css" href="style.css" />
    <?php if((isset($_GET['section'])) AND ($_GET['section']=="booking") AND (isset($_GET['action'])) AND ($_GET['action']=="edit")) {  
    
    $query = mysql_query("SELECT * FROM booking WHERE id='$id'");
    while ($row = mysql_fetch_object($query)) {
    					
    $id=$row->id;
    
    if($id=="1") {
    
    echo("<script type=\"text/javascript\">
    
    document.getElementById('mydiv').style.display = 'block';
    										
    </script>"); 
    
    }
    
    }
    
    }
    
    ?>
    </head>
    but it doesn't work ..... when you view page's source in the browser, this is what comes up before the end of head section:

    <script type="text/javascript">

    document.getElementById('flavours').style.display = 'block';

    </script>


    so php seems to work, but js doesn't for some reason, i still can't see the #mydiv. what am i doing wrong guys ?
    Last edited by elem; 09-25-2011 at 04:49 AM.

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Posts
    974
    Thanks
    19
    Thanked 212 Times in 210 Posts
    Quote Originally Posted by elem View Post
    i'm trying to change hidden div's display to block if the certain conditions in php will be true. so what i have is:

    but it doesn't work ..... when you view page's source in the browser, this is what comes up before the end of head section:

    <script type="text/javascript">

    document.getElementById('flavours').style.display = 'block';

    </script>


    so php seems to work, but js doesn't for some reason, i still can't see the #mydiv. what am i doing wrong guys ?
    you can only use document.getElementById after
    the document is ready, you should put that in
    aa onload handler , or at the bottom of page
    just before </body>

  • Users who have thanked DaveyErwin for this post:

    elem (09-25-2011)

  • #3
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,715
    Thanks
    25
    Thanked 660 Times in 659 Posts
    An example to show you what DaveyErwin said.

    Code:
    <?php
    $id = "1";  // change 1 to something else and div does not appear
    ?>
    <html><head></head>
    <body>
    <div id="mydiv" style="display:none;"> Just a bunch of Monkeys</div>
    
    <script type="text/javascript">
    var test = <?php echo $id; ?>;
    if (test == '1')
    	document.getElementById('mydiv').style.display = 'block';
    </script>
    </body></html>

  • Users who have thanked sunfighter for this post:

    elem (09-25-2011)

  • #4
    New Coder
    Join Date
    Sep 2011
    Posts
    35
    Thanks
    18
    Thanked 1 Time in 1 Post
    Thanks a lot gents, indeed script was just in a wrong spot.

    Thanks again


  •  

    Posting Permissions

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