Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6975501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:22:36+00:00 2026-05-27T17:22:36+00:00

I have a while loop that shows the results from a select query. Then

  • 0

I have a while loop that shows the results from a select query. Then for each result that was returned by the query, there is a link that once clicked, will show a message form. Clicking again the link, the message form will be hidden. It was made using a JQuery plugin. The problem now is, if I clicked the link, all the results will show the message form instead of showing only one, which should be from the result where the link was clicked. The code looks like this:

PHP + HTML

<?php
    $query = mysql_query(......) or die(mysql_error());
    while($row = mysql_fetch_assoc($query)){
        $id = $row['Id'];
        echo "<a class='hideMessageForm' href='#foo?id=" . $row['Id'] . "'>" . $row['Name'] . "</a>" .       
       "<div id='foo' class='showMessageForm'>
           <form action='process.php' method='post'>
              <input type='hidden' name='id' value='" .$id "'/>
              <input type='text' name='message' value=''/>
              <input type='submit' name='sendMessage' value='Send Message'/>
           </form>
       </div>";
    }
?>

JavaScript

 $(document).ready(function(){

    $(".showMessageForm").hide();
    $(".hideMessageForm").show();

    $('.hideMessageForm').click(function(){
    $(".showMessageForm").slideToggle();
    });

 });

Let me explain the thing I want to happen

For example, the query returned 3 results (result #1, #2, #3). Each result shows the link that refers to the foo div. If I clicked the link in result #1, the #2 and #3 will also popup the message form. Clicking the link from any of the 3 results will show 3 message form. I only want the result where the link was selected to be the only one to popup the message form. Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:22:36+00:00Added an answer on May 27, 2026 at 5:22 pm

    This is what you want. http://jsfiddle.net/qEeZf/

    You are displaying / hidding all elements of the class. You just want to display or hide the next element of the link clicked. ( Seeing your PHP code, I am assuming the div will always be the next element after the link).

    $(document).ready(function(){
    
        $(".showMessageForm").hide();
        $(".hideMessageForm").show();
    
        $('.hideMessageForm').click(function(){
        $(this).next(".showMessageForm").slideToggle();
        });
    
     });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script that uses a simple while loop to display a progress
So I have a Linux program that runs in a while(true) loop, which waits
The while loop I have while reading in from a file doesn't break. I'm
I have a tabled view in a while loop, where a user can view
I'm trying to understand how a while loop looks in IL. I have written
I have a Label, whose content is displayed by a while loop. when i
Using parent child relationship where a parent can have children while each child has
I'm trying to setup a loop in Wordpress that will show all posts from
I have a Linq query that will search a column for a word and
I have a resultSet that has a different number of results every time, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.