jquery tabs and search form in one tab

jquery tabs and search form in one tab

I am a middle school geography teacher learning web programming.

 

For my school, I am creating a single-page multi-tab portal with four jquery tabs.  I'd like the fourth tab to contain a form and also search & display MySQL query results.

 

My problem is, on the fourth tab, once I enter the search term and hit the "Search" button, the results are not loading in the fourth tab.  They are loading on a separate page: http://localhost/notes_search.php

 

How could I get the results to appear in the fourth tab, below the search form? 

 

Another way to look at this problem: I am successfully able to get the (1) tabs functioning separately (2) search results load in a single (no tab) page separately.  I am missing something as I try to combine these two features.

 

Please help.  Thank you very much.

-Susana

 

#######################

 

This is what I have on the php file for the fourth tab (page_4.php):

 


  1. <div id="notescontainer">

  2.           <div>

  3.                    <form method="post" action="notes_search.php">

  4.                              <input type="text" name="search" id="notes_search_box" class="notes_search_box"/>

  5.                              <input type="submit" value="Search" class="notes_search_button" /><br />

  6.                    </form>

  7.           </div>    

  8.           <div>

  9.                    <div id="notes_searchresults">Search results :</div>

  10.                    <div id="notes_results" class="update"></div>

  11.           </div>

  12. </div>

  13.  

 

#######################

 

This is what I have for search and display: notes_search.php

 


  1. <?php

  2.  

  3.  

  4. define('INCLUDE_CHECK',true);

  5.  

  6. require 'connect.php';

  7.  

  8.  

  9. //if we got something through $_POST

  10. if (isset($_POST['search'])) {

  11.  

  12.           // never trust what user wrote! We must ALWAYS sanitize user input

  13.     $word = mysql_real_escape_string($_POST['search']);

  14.  

  15.           // build your search query to the database

  16.           $result = mysql_query("select * from notes where notes like '%".$word."%'");

  17.  

  18.     // get results

  19.           while($row = mysql_fetch_array($result))

  20.           {

  21.                    echo "<p>".$row['notes'];

  22.           }

  23. }

  24. ?>

  25.  

#######################

 

And finally, here's the JavaScript on the main page of the portal: index.php

 

  1.    <SCRIPT>

  2.    

  3. $(function() {

  4.  

  5.     $(".notes_search_button").click(function() {

  6.         // getting the value that user typed

  7.         var searchString    = $("#notes_search_box").val();

  8.         // forming the queryString

  9.         var data            = 'search='+ searchString;

  10.         

  11.         // if searchString is not empty

  12.         if(searchString) {

  13.             // ajax call

  14.             $.ajax({

  15.                 type: "POST",

  16.                 url: "notes_search.php",

  17.                 data: data,

  18.                 beforeSend: function(html) { // this happens before actual call

  19.                     $("#notes_results").html('');

  20.                     $("#notes_searchresults").show();

  21.                     $(".word").html(searchString);

  22.                },

  23.                success: function(html){ // this happens after we get results

  24.                     $("#notes_results").show();

  25.                     $("#notes_results").append(html);

  26.               }

  27.             });  

  28.         }

  29.         return false;

  30.     });

  31. });

  32.  
  33.           </script>