putradnata

Create Dynamic Search Box using Ajax [ with table ]

Jul 27th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.63 KB | None | 0 0
  1. <!-- Your Search Box [ with input type text ] -->
  2. <input type="text" name="your_input_name" id="your_input_id" class="form-control"> //when u type a letter or alphabet, search will automaticaly work, no need to click button
  3.  
  4. <!-- Your Table -->
  5. <table class="table table-bordered">
  6.     <thead class="thead">
  7.         <tr>
  8.             <th style="color: #ffffff"> Y </th>
  9.             <th style="color: #ffffff"> o </th>
  10.             <th style="color: #ffffff"> u </th>
  11.             <th style="color: #ffffff"> d </th>
  12.             <th style="color: #ffffff"> e </th>
  13.             <th style="color: #ffffff"> f </th>
  14.             <th style="color: #ffffff"> i </th>
  15.             <th style="color: #ffffff"> n </th>
  16.             <th style="color: #ffffff"> e </th>
  17.         </tr>
  18.     </thead>
  19.     <tbody id="your_tbody_id" class="tbody"></tbody>
  20. </table>
  21.  
  22. <!-- Process [ using ajax ] -->
  23. <script type="text/javascript">
  24.   $(document).ready(function(){
  25.     $("#your_input_id").keyup(function(){ //keyup function, right use if u search with name or address which that's match with your data in your database
  26.       var new_variable = $("#your_input_id").val(); //define variable and get the value from your_input_id
  27.       $("#your_tbody_id").html("<tr><td colspan=12><img src='img/load.gif'/></td></tr>") // if u have Loading.gif or etc,u can use that here
  28.         $.ajax({ //ajax process
  29.           url: "your_process_page.php",
  30.           data: "new_variable="+new_variable,
  31.           cache: false,
  32.           success: function(msg){
  33.             $("#your_tbody_id").html(msg); //if success, the results will appear in your_tbody_id
  34.           }
  35.         });
  36.     });
  37.   });
  38. </script>
Advertisement
Add Comment
Please, Sign In to add comment