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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.