Jump to content

Help with some code


kwdelre

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/207776-help-with-some-code/
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/207776-help-with-some-code/#findComment-1086161
Share on other sites

Archived

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

×
×
  • Create New...

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.