Jump to content

Archived

This topic is now archived and is closed to further replies.

nick1

The Effect I'm Trying to Achieve...

Recommended Posts

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:

[a href=\"http://isohunt.com/torrents.php?ihq=nature&ext=&op=and\" target=\"_blank\"]http://isohunt.com/torrents.php?ihq=nature&ext=&op=and[/a]

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*

Share this post


Link to post
Share on other sites
Looks more like JavaScript, remember - PHP is a server side language.

Share this post


Link to post
Share on other sites
You don't need php to do this, you need javascript/css

1. create a div that contains all your comments, give it an id or a class that you refer to in your css file

<div id='comment'>
comments go here
</div>

2. in the css, set 'display: none;' for the div that contain comments
3. create a button on your page
4. add the onclick event (javascript) to the button

<input type='button' value='show comments' onclick="document.getElementById('comment').style.display=block;">

this is all from the top of my head, I usually keep javascript language reference nearby. If you want to do some other things or just to keep things readable in your code, you could create a function that doest the same.

<input type='button' value='show comments' onclick="showcomments()">

<script type='javascript'>
var comment = document.getElementById('comment').style;
comment.display = 'block';
</script>

Warning: this will NOT create the slider effect, you need something like on [a href=\"http://script.aculo.us\" target=\"_blank\"]http://script.aculo.us[/a] for that, don't ask me questions about it, cos I just know it exists, never used it

Share this post


Link to post
Share on other sites
Greetings,

Thank you for trying to help me out with this small project. I very much appreciate your ideas and time.
Unfortunately the only thing I see when I try to execute this code is the button. I'm not sure why it isn't working.

Here is my index.html page:

[code]<html>
<head>
<title></title>
<link rel="stylesheet" href="index.css" type="text/css" media="screen" />
</head>

<body>

    <div id='comment'>
        comments go here
    </div>

    <input type='button' value='show comments' onclick="document.getElementById('comment').style.display=block;">

</body>
</html>[/code]

And here is my index.css page:

[code]#comment {
  display: none;
}[/code]

Sorry, I don't know Java at all. I tried researching some things on Google, however, that lead to lots of frustration trying to troubleshoot something I don't understand. What do you think needs adjusting in this code?

Thank you for your continued help,

*Nick*

Share this post


Link to post
Share on other sites
you need to ask this question on javascript forum this is php forum not trying to be rude but you're more likely to find a good answer there.

Share this post


Link to post
Share on other sites
I'll move this to our JavaScript forum. Please be aware, Java and JavaScript are two very different languages!

Share this post


Link to post
Share on other sites
Hi there,

Try this code example,,
html/javascript part is about:
[code]
<html>
<head>
<link rel="stylesheet" href="index.css" type="text/css" media="screen" />
</head>
<body>

<script>
function ShowComments(comment_id,text_id,nb)
{
var tochange="<span class=\"comments\" onclick=\"HideComments('"+comment_id+"','"+text_id+"',"+nb+");\"";
tochange=tochange+" style=\"background-color:#ECECD9;\"";
tochange=tochange+" onmouseover=\"\"";
tochange=tochange+" onmouseout=\"\">";
tochange=tochange+"see the comment "+nb+"</span>";
document.getElementById(comment_id).innerHTML=tochange;
document.getElementById(text_id).style.display="block";
}

function HideComments(comment_id,text_id,nb)
{
var tochange="<span class=\"comments\" onclick=\"ShowComments('"+comment_id+"','"+text_id+"',"+nb+");\"";
tochange=tochange+" style=\"background-color:#CAD9EA;\"";
tochange=tochange+" onmouseover=\"this.style.backgroundColor='#ECECD9';\"";
tochange=tochange+" onmouseout=\"this.style.backgroundColor='#CAD9EA';\">";
tochange=tochange+"see the comment "+nb+"</span>";
document.getElementById(comment_id).innerHTML=tochange;
document.getElementById(text_id).style.display="none";
}
</script>

<div id="comment1">
<span class="comments" onmouseover="this.style.backgroundColor='#ECECD9';" onmouseout="this.style.backgroundColor='#CAD9EA';" onclick="ShowComments('comment1','text1',1);" >see the comment 1</span>
</div>
<div id="text1" class="text" style="display:none;">
<table border=1 align=center width="700px">
<tr><td style="background-color:#CAD9EA;">
This is my first comment,...<br>hoping it's a nice one,...
</td>
</tr>
</table>
</div>
<div id="comment2">
<span class="comments" onmouseover="this.style.backgroundColor='#ECECD9';" onmouseout="this.style.backgroundColor='#CAD9EA';" onclick="ShowComments('comment2','text2',2);" >see the comment 2</span>
</div>
<div id="text2" class="text" style="display:none;">
<table border=1 align=center width="700px">
<tr><td style="background-color:#CAD9EA;">
& this is my second comment,,  :)
</td>
</tr>
</table>
</div>
</body>
</html>
[/code]
& index.css file:
[code]
.comments {
    cursor:pointer;
    background-color:#CAD9EA;
    border: 1px solid gray;
    width:800px;
    padding:0.1em;
}

.text {
    background-color:#ECECD9;
    border: 1px solid gray;
    border-top:none;
    width:800px;
    padding:0.1em;
}
[/code]
it gives also the slider effect using onmouseout/onmouseover properties,

Hoping it helps,,

l8tr,,

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.