title: Using Ajax to livesearch mySql and return results hidden by jquery toggle
body: <p>How do i get the toggle to function in the search results? I am not sure what I need to do to get this to work.  Have a MySQL db, and am using AJAX to perform live search.  The search populates in table rows, and I want to hide certain rows unless user clicks "toggle".  The code to toggle and populate table works on a summary page, but I need it to work after search.</p>
  
  <pre><code>&lt;?php
  @session_start(); //start session
  ?&gt;
  
  &lt;!DOCTYPE html&gt;
  
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Admin Search&lt;/title&gt;
          &lt;link rel="stylesheet" type="text/css" href="generic.css"&gt;
      &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"&gt;
          $(document).ready(function(){
            $(".seek").click(function(){
              $(".hide").toggle();
            });
          });
  
          $(document).ready(function(){
            $(".saButton").click(function(){
              $(".short").toggle();
            });
          });
          $(document).ready(function(){
            $(".eaButton").click(function(){
              $(".essayans").toggle();
            });
          });
          &lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
  var xmlReq;
  function processResponse(){
     if(xmlReq.readyState == 4){
         var place = document.getElementById("placeholder");
         place.innerHTML = xmlReq.responseText;
    }
  }
  
     function loadResponse(){
        // create an instance of XMLHttpRequest 
        xmlReq = new XMLHttpRequest();
        xmlReq.onreadystatechange = processResponse;
  
    xmlReq.open("POST", "findResults.php", true);
  
    //read value from search bar
    parameter = "keyword=" + encodeURI(document.forms["search"].keyword.value);
  
    //send headers
    xmlReq.setRequestHeader("Content-type", 
                "application/x-www-form-urlencoded");
    xmlReq.setRequestHeader("Content-length", parameter.length);
    xmlReq.setRequestHeader("Connection", "close");
  
    xmlReq.send(parameter);
    return false;
     }
  &lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;?php include "generic_menu.php"; ?&gt;
      &lt;br&gt;&lt;br&gt;
  
      &lt;nav&gt;  &lt;!--Menu for the Admin functions --&gt;      
          &lt;ul class="navigation"&gt;
              &lt;li&gt;&lt;a href="adminsOnly.php"&gt;&lt;input type="button" 
                                          value="Admin Home"&gt;&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href="surveys.php"&gt;&lt;input type="button" 
                          value="Completed Surveys"&gt;&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href="search.php"&gt;&lt;input type="button" 
                                  value="Search the Surveys"&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
      &lt;/nav&gt;
  
      &lt;div class="pageContent"&gt; 
          &lt;h1 class='pageTitle'&gt;Search all Surveys Submitted&lt;/h1&gt;
  
          &lt;br&gt;&lt;hr&gt;&lt;br&gt;
  
          &lt;div class="qbox"&gt; &lt;!--Search Input Field --&gt;   
              &lt;?php
                  session_regenerate_id();
  
                  if (!isset($_SESSION['authenticated']) OR !$_SESSION['authenticated'] == 1) { 
                      die ("ERROR: Unauthorized access!"); 
                  } 
                  else { 
                    echo  '
  
             &lt;!--Search Input--&gt;
           &lt;form method="POST" name="search" action="" class="search"&gt;
  
      &lt;h2&gt;Search:&lt;input type="text" name="keyword" onKeyUp="return loadResponse();"&gt;&lt;/h2&gt;
          &lt;/form&gt;';
                  } 
              ?&gt;     
          &lt;/div&gt;&lt;br&gt;&lt;!--END Search Input Field --&gt;
  
          &lt;!--Search RESULTS Field --&gt;
          &lt;div class="qbox"&gt; 
          &lt;h2&gt;Search Results:  &lt;/h2&gt;&lt;br&gt;&lt;br&gt;     
      &lt;div id="placeholder"&gt;&lt;/div&gt;
          &lt;!--This is for the search results --&gt;
          &lt;/div&gt;&lt;br&gt;&lt;!--END Search RESULTS Field --&gt;
      &lt;/div&gt;&lt;!--end page content --&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p>And this is the rest:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
   &lt;title&gt;Display Results&lt;/title&gt;
  &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"&gt;
          $(document).ready(function(){
            $(".seek").click(function(){
              $(".hide").toggle();
            });
          });
  
          $(document).ready(function(){
            $(".saButton").click(function(){
              $(".short").toggle();
            });
          });
          $(document).ready(function(){
            $(".eaButton").click(function(){
              $(".essayans").toggle();
            });
          });
          &lt;/script&gt;
   &lt;/head&gt;
   &lt;body&gt;
  &lt;?php
   $conn = new mysqli("localhost", "limited_user", 
  "this*password", "mcanazon");
  
    if (mysqli_connect_errno()){
        echo 'Cannot connect to database: ' . 
            mysqli_connect_error($conn);
    }
    else{
       //read keyword from database
       if(!empty($_POST["keyword"])){
          $search = "%".$_POST["keyword"]."%"; 
  
          // create prepared statement 
         if ($query = mysqli_prepare($conn, 
         "SELECT surveyTable.email, gender, ageGroup,
     dropdown, dropdown2, checkval, shortA, essay,
     response1, response2, response3, response4, system_date
     FROM surveyTable
     JOIN surveyTable2 ON surveyTable.id=surveyTable2.id
     WHERE concat(surveyTable.email, gender, ageGroup)  like ?")) {                  
  
         // bind parameters
         mysqli_stmt_bind_param ($query, "s", $search);
  
          //run the query and keep results in $result variable
          mysqli_stmt_execute($query);
  
          // bind variables to prepared statement 
          mysqli_stmt_bind_result($query, $email, $gender, $ageGroup, $dropdown, $dropdown2, $checkval, 
                  $shortA, $essay, $response1, $response2, $response3, $response4, $system_date);
  
        // fetch values 
          while (mysqli_stmt_fetch($query)) {
              echo "
  
       &lt;div class='qbox'&gt;&lt;br&gt;&lt;table border='1'&gt;&lt;tr&gt;&lt;th class='admintables'&gt;Email&lt;/th&gt;&lt;th class='admintables'&gt;Date&lt;/th&gt;&lt;/tr&gt;
                                                  &lt;tr&gt;&lt;td&gt;$email&lt;/td&gt;&lt;td&gt;$system_date&lt;/td&gt;&lt;/tr&gt;
                  &lt;/table&gt;
                  &lt;br&gt;&lt;br&gt;
                  &lt;table border='1'&gt;
                  &lt;tr&gt;&lt;th class='admintables'&gt;Gender&lt;/th&gt;&lt;th class='admintables'&gt;Age Group&lt;/th&gt;&lt;/tr&gt;
                  &lt;tr&gt;&lt;td&gt;$gender&lt;/td&gt;&lt;td&gt;$ageGroup&lt;/td&gt;&lt;/tr&gt;
                  &lt;/table&gt;
                  &lt;br&gt;&lt;br&gt;
                  &lt;table border='1'&gt;
                  &lt;tr&gt;&lt;th class='admintables'&gt;This is a question with answer choices in drop-down format.&lt;/th&gt;&lt;/tr&gt;
                  &lt;tr&gt;&lt;td&gt;Option:$dropdown&lt;/td&gt;&lt;/tr&gt;
                  &lt;/table&gt;
                  &lt;br&gt;&lt;br&gt;
                  &lt;table border='1'&gt;
                  &lt;tr&gt;&lt;th class='admintables'&gt;This is another question with a drop-down format.&lt;/th&gt;&lt;/tr&gt;
                  &lt;tr&gt;&lt;td&gt;Favorites: $dropdown2&lt;/td&gt;&lt;/tr&gt;
                  &lt;/table&gt;
                  &lt;br&gt;&lt;br&gt;
                  &lt;table border='1'&gt;
                  &lt;tr&gt;&lt;th class='admintables'&gt;The following are checkboxes. You may choose more than one,&lt;br&gt;
                      but you must choose at least one:&lt;/th&gt;&lt;/tr&gt;
                  &lt;tr&gt;&lt;td&gt;Boxes Checked: $checkval&lt;/td&gt;&lt;/tr&gt;
                  &lt;/table&gt;
                  &lt;br&gt;&lt;br&gt;
                  &lt;table border='1'&gt;
                  &lt;caption class='admintables'&gt;&lt;b&gt;Please tell us how likely you agree with the following:&lt;b&gt;&lt;button class='seek'&gt;Answer&lt;/button&gt;&lt;/caption&gt;
                  &lt;tr class='hide' style='display:none'&gt;&lt;th class='admintables'&gt;&lt;p&gt;Response for the 1st statement:&lt;/p&gt;&lt;/th&gt;&lt;td&gt;&lt;p&gt;$response1&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
                  &lt;tr class='hide' style='display:none'&gt;&lt;th class='admintables'&gt;&lt;p&gt;Response for the 2nd statement:&lt;/p&gt;&lt;/th&gt;&lt;td&gt;&lt;p&gt;$response2&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
                  &lt;tr class='hide' style='display:none'&gt;&lt;th class='admintables'&gt;&lt;p&gt;Response for the 3rd statement:&lt;/p&gt;&lt;/th&gt;&lt;td&gt;&lt;p&gt;$response3&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
                  &lt;tr class='hide' style='display:none'&gt;&lt;th class='admintables'&gt;&lt;p&gt;Response for the 4th statement:&lt;/p&gt;&lt;/th&gt;&lt;td&gt;&lt;p&gt;$response4&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
                  &lt;/table&gt;
                  &lt;br&gt;&lt;br&gt;
                  &lt;table border='1'&gt;
                  &lt;caption class='admintables'&gt;&lt;b&gt;What do you think of this short answer question? &lt;b&gt;  &lt;button class='saButton'&gt;Answer&lt;/button&gt;&lt;/caption&gt;
                  &lt;tr class='short' style='display:none'&gt;&lt;td&gt;&lt;p&gt;$shortA &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
                  &lt;/table&gt;
                  &lt;br&gt;&lt;br&gt;
                  &lt;table border='1'&gt;
                  &lt;caption class='admintables'&gt;&lt;b&gt;In one paragraph, what do you &lt;br&gt;think of this paragraph answer question?&lt;b&gt;  &lt;button class='eaButton'&gt;Answer&lt;/button&gt;&lt;caption class='caption'&gt;
                  &lt;tr class='essayans' style='display:none'&gt;&lt;td&gt;&lt;p&gt;$essay&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
                  &lt;/table&gt;
                  &lt;br&gt;
                  &lt;/div&gt;
                  &lt;br&gt;&lt;br&gt;&lt;br&gt;";
          }
  
          //free memory 
          mysqli_stmt_close ($query);
  
  
          } else 
            echo "Error: " . mysqli_error($conn);
        } else { 
            echo "Please enter a search term";
        }
  
       mysqli_close($conn);
   }
  ?&gt;
   &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Thanks so much, I am extremely new to this (only used ajax once and never all these languages compiled together).</p>