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 985127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:07:16+00:00 2026-05-16T05:07:16+00:00

I am using jQuery to load the search results from a php class when

  • 0

I am using jQuery to load the search results from a php class when the user enters a search term. The problem is that jQuery runs and executes the functions as required the first time round on the main page, but when the user enters a search keyword and the results are loaded from the class file on the same page via ajax, jQuery does not execute the function required.

What I want to do is, when the search results are loaded on the main page, it should only show the Quote and the author, not the arabic and reference. When the user clicks on the Quote, it should act like an accordian, toggling the div container of arabic and reference.

However, while jQuery works great loading the results from the class file, it doesn’t execute to hide the container of arabic and reference when it’s loads the search results nor does it run the click event when the user clicks on the Quote to show the container, as firebug shows.

index.php:

    <script type="text/javascript">
    $(function() {

                $(".bsearch")
                    .keydown(function() {
                         //create post data
                          var postData = { 
                            "search" : $(this).val()
                          };

                          //make the call
                          $.ajax({
                            type: "POST",
                            url: "quotes_in.php",
                            data: postData, //send it along with your call
                            success: function(response){
                                $("#left").html(response);
                            }
                          });

                    }),




                $("div#smore").hide();
                    //toggle the componenet with class msg_body
                $("p#s_quotes").click(function()
                    {
                      $(this).next("div#smore").slideToggle(200);
                    }),         



                });

    </script> 

 <!-- Begin Left Column -->
        <div id="left">

        </div>
<!-- End Left Column -->

Quotes_in.php:

include_once "inc/class.quotes.inc.php";
$quotes = new Quotes($db);


if (isset($_POST['search'])) 
    $quotes->searchQuotes();

The function in the class file which formats the search:

   ---SQL QUERY for SEARCH---
    public function formatSearch($row, $search) 
                {


                    return "<div class=\"swrap\">"
                    . "<p id=\"s_quotes\">&nbsp;" . $cQuote . "&nbsp;</p>"
                    . "<div id=\"smore\"><p id=\"s_arabic\">" . $this->h($row['cArabic']) . "</p>"
                    . "<p id=\"s_reference\"><span class=\"source\">Source:</span> " . $this->h($row['vReference']) . "</p></div>"
                    . "<p id=\"s_author\"><b>-</b>&nbsp;" . $this->h($row['vAuthor']) . "</p></div>"; 
                }
  • 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-16T05:07:17+00:00Added an answer on May 16, 2026 at 5:07 am

    It’s becasue your quote elements are being replaced, so you need to use .live() or .delegate() handler here, instead of this:

    $("p#s_quotes").click(function() {
      $(this).next("div#smore").slideToggle(200);
    });         
    

    You need this:

    $("p#s_quotes").live('click', function() {
      $(this).next("div#smore").slideToggle(200);
    });    
    

    Unlike .click() which binds an event handler to the element, which is getting replaced…and so the event handler vanishes too, .live() adds an event handler to document which listens for a click from p#s_quotes (this can be just #s_quotes) to bubble up, and executes the handler if that happens.


    For the hiding portion, either call $("#smore").hide(); again in your success callback, or create them hidden, like this:

    <div id=\"smore\" style='display: none;'>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im using jQuery/PHP/MySql to load twitter search results on the page but limited to
I am using jquery .load() method to load results of a search within a
Hi I'm using JQuery tabs http://jqueryui.com/demos/tabs/ with search results being returned from my server
There's placeholder on the page that is loaded asynchronously using jQuery load method. Page
I am currently using jQuery to load a variable php layout depending on the
After loading a PHP template (using jQuery's load function), this simple script won't make
i m a beginner... here i m using the jquery for showing search results
I am using the jquery .load() method for a search. I have figured out
I'm using jquery.flickr-1.0.js to search flickr for images in my application. The problem i'm
I was wondering whether the instant search using jQuery would cause a massive load

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.