kwdelre Posted July 14, 2010 Share Posted July 14, 2010 I was hoping someone could help me out here. Here is what I would like to do: I am creating an FAQ page. I will have a list of questions that are links. When the user clicks on a particular link I want to "print" some text below it from a separate php file. In the php file I assume I will just define each answer as a variable. What would the coding look like on the faq page to activate the php variable on click? Also, I would like it to go away on second click. Thanks for the help guys. Quote Link to comment Share on other sites More sharing options...
trq Posted July 14, 2010 Share Posted July 14, 2010 The solution to your problem is Javascript. PHP executes server-side. Quote Link to comment Share on other sites More sharing options...
kwdelre Posted July 14, 2010 Author Share Posted July 14, 2010 Ahhh ok, Is this a very code intensive task? Quote Link to comment Share on other sites More sharing options...
trq Posted July 14, 2010 Share Posted July 14, 2010 Not really, especially if you used a framework like jQuery. here is the code I wrote for a faq at work. $(document).ready(function() { $('.answer').hide(); $("a[name^='faq-']").each(function() { $(this).click(function() { if($("#"+this.name).is(':hidden')) { $("#"+this.name).fadeIn('slow'); } else { $("#"+this.name).fadeOut('slow'); } }); }); $('.answer').click(function() { $(this).fadeOut(); }); }); All you need then is some pretty simply markup. <ul class="faq"> <li><a name="faq-1">This is question 1</a> <div class="answer" id="faq-1"> <p>This is the answer to question 1</p> </div> </li> <li><a name="faq-2">This is question 2</a> <div class="answer" id="faq-2"> <p>This is the answer to question 2</p> </div> </li> </ul> Quote Link to comment Share on other sites More sharing options...
kwdelre Posted July 14, 2010 Author Share Posted July 14, 2010 Awesome, thanks man! I just got the code from http://forums.pligg.com/questions-comments/15598-how-make-digg-style-faq-page-javascript-jquery.html and it's working just perfect! 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.