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 Coder
    Join Date
    Nov 2005
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    The Effect I'm Trying to Achieve...

    I'm not sure how to describe the effect I'm trying to achieve, so I'll point out a website that has implemented what I'd like to do:

    http://isohunt.com/torrents.php?ihq=nature&ext=&op=and

    Notice that a 'drop down' menu appears when a title is clicked on.
    How is this done? Can PHP accomplish this neat feature?
    On my website I have a blog and I want readers to have the option of leaving a comment about a blog entry.
    But I don't want all the comments displayed at once. At first, I only want to display the number of comments that exist for a specific blog entry. Then make that number a hyperlink that drops down the comments for that specific blog entry. Make sense?

    So basically:

    ------------------------
    | Blog entry here............|
    | blah blah blah blah blah |
    | blah blah blah blah blah |
    | blah blah blah blah blah |
    | blah blah blah blah blah |
    | blah blah blah blah blah |
    ------------------------

    There are 5 comments available. (clicking the #5 would display the comments)

    --------------------------
    |comment 1: blah blah blah |
    --------------------------

    --------------------------
    |comment 2: blah blah blah |
    --------------------------

    --------------------------
    |comment 3: blah blah blah |
    --------------------------

    --------------------------
    |comment 4: blah blah blah |
    --------------------------

    --------------------------
    |comment 5: blah blah blah |
    --------------------------

    Close Comments (this feature would make the comments disappear again)

    Any help would be greatly appreciated! Thank you for your time,

    *Nick*

  • #2
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    no. PHP is a server-side language. Once the page has loaded, php is done with it.
    What you're looking for is javascript, which is a client side scripting language, client side scripting means its easy to see hows its done by viewing the source code.
    In this particular example we look at code for those table rows - we know that the desired effect happens when we click on the item so we look for an onclick event...

    Code:
    onclick="servOC(1,'/btDetails.php?ihq=nature&id=10950472','#cad9ea')"
    ok, but what does servOC do?

    Time to look at the external js files.

    Code:
    function servOC(i, href, nColor) {
      var trObj = (document.getElementById) ? document.getElementById('ihtr' + i) : eval("document.all['ihtr" + i + "']");
      var nameObj = (document.getElementById) ? document.getElementById('name' + i) : eval("document.all['name" + i + "']");
      var ifObj = (document.getElementById) ? document.getElementById('ihif' + i) : eval("document.all['ihif" + i + "']");
      if (trObj != null) {
        if (trObj.style.display=="none") {
          trObj.style.display="";
          nameObj.style.background="#ECECD9";
          if (!ifObj.src) ifObj.src = href;
          smoothHeight('ihif' + i, 0, 210, 42, 'o');
        }
        else {
          nameObj.style.background=nColor;
          smoothHeight('ihif' + i, 210, 0, 42, 'ihtr' + i);
        }
      }
    }
    so this function gets passed a number, a url and a colour. First it looks to see if it can find an object with the name ihif + the number that was passed in, eg ihif1.
    If you look in the source code you will see that ihif1 is an iframe.
    Then the function looks to see if the object ihif1 is being displayed, if it is, it hides it, if it isnt it, sets the src attribute of the iframe to the url passed into the function and the background colour of the table cell name1 to the colour that was passed in.


  •  

    Posting Permissions

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