TeddyKiller Posted May 3, 2010 Share Posted May 3, 2010 I have an href for "View Comments" what should happen is when you click that.. a div underneath should display the comments etc.. (stick with the div because I can do the rest) This is simple however.. there may be multiple "view comments" for different posts. I could use a javascript function. Do an onclick href event, and call the function with the div name. Multiple divs will be used (It's in a while function) what I'd do.. is do specific ID's relating to the while. Allowing the divs to have different names. comment-1, comment-2 for example. Sorry if I'm confusing you. This will allow me to have multiple comment divs, although I would like to close every other div thats open. So.. href to open 1 div. When you click on another href to open another div, it'll have 2 divs open. When I only want it to open once at a time. If I make sense. How can I do it? If i've had no replies by the time I finish the first bit.. i'll post the code. Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted May 3, 2010 Author Share Posted May 3, 2010 This would be the php. The onclick calls the function "showComments" with the comment id. (Unique for that post) The div to be displayed, also has the unique ID. So when the javascript function gets called.. It'll open the div. echo '<a href="#" onclick="showComments(\'comment'.$row['id'].'\')">View Comments(0)</a>' . '<div id="comment'.$row['id'].'" style="display:none;"> stuff </div>'; Javascript for the function function showComments(Comment_Menu) { Comment_Menu = document.getElementById(Comment_Menu); if(Comment_Menu.style.display == "none") { Comment_Menu.style.display = "block"; } } This works for multiple divs. (The echo is in a while function, so it gets displayed multiple times, each one having different div id) Although.. what I want is that when a div opens, all remaining divs that are opened, to be closed. Hope this makes more sense. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.