SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Enthusiast Aknot's Avatar
    Join Date
    May 2004
    Location
    Scandinavia
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Open and close DIV area with JS and PHP

    Hi everyone!

    I have this simple Javascript to open and close div areas.

    <script language="javascript" type="text/javascript">
    function showDiv(theDiv) {
    var elem = document.getElementById(theDiv);
    elem.style.display = (elem.style.display == "none")? "" : "none";
    }
    </script>

    Now I want to be able to open a div area, when sending a GET, eg /file.php?showDiv=5642

    I have several divs on the same page, and when entering this page from special link, I want to be able to open that div area. Based on id.

    Is that possible? Hope tou understand what I mean...
    Thanks!

  2. #2
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    813
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do you have the code where you attach your showDiv function, is it bind to a certain object closure?

  3. #3
    SitePoint Enthusiast Aknot's Avatar
    Join Date
    May 2004
    Location
    Scandinavia
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    This is what I have

    <div id="<?php echo($row['id']); ?>" style="display:none;>Some Text bla bla</div>

    <a href="#" onclick="showDiv('<?php echo($row['id']); ?>');return false;">Show</a>

    Thanks

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi!

    Try to put on your page where divs are something like this:

    PHP Code:
    <?
    if($_GET) {
    if(
    $_GET['some id which tells the page which div to show']) echo"<script type='text/javascript'>showDiv(div to show);</script>";
    }
    ?>
    It works for me. I have this in the bottom of the page.
    Hope this helps.

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, it should be like this:

    PHP Code:
    <?
    if($_GET) {
    if(
    $_GET['your id']=='value which tells the page which div to show') echo"<script type='text/javascript'>showDiv(div to show);</script>";
    }
    ?>

  6. #6
    SitePoint Enthusiast Aknot's Avatar
    Join Date
    May 2004
    Location
    Scandinavia
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking

    Quote Originally Posted by bosko View Post
    PHP Code:
    <?
    if($_GET) {
    if(
    $_GET['your id']=='value which tells the page which div to show') echo"<script type='text/javascript'>showDiv(div to show);</script>";
    }
    ?>
    Works great!
    Thanks A L


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
  •