Prefilled Search Box Using PHP/Jquery -


i have search field on page allows users search record.

i have php file displays records , has search box @ top using jquery filter results user types in. want send user's search results previous page search box results filtered search term.

i able bring on search term using code search box:

        <input type="text" id="filtersearch" placeholder="search name or phone number" value="<?php echo $search; ?>"> 

but while transfers search field, results aren't filtered when page opened. have click on search box , hit enter update results.

this script i'm using

$(document).ready(function() { var $rows = $('#orders tbody tr'); $('#filtersearch').keyup(function() {     var val = $.trim($(this).val()).replace(/ +/g, ' ').tolowercase();      $rows.show().filter(function() {         var text = $(this).text().replace(/\s+/g, ' ').tolowercase();         return !~text.indexof(val);     }).hide(); });  }); 

any appreciated.

also, there way limit filtering on search fields or columns?

to filter results on page load, can trigger key event on element on document ready this:

$(document).ready(function() {     var $rows = $('#orders tbody tr');     $('#filtersearch').keyup(function() {         var val = $.trim($(this).val()).replace(/ +/g, ' ').tolowercase();          $rows.show().filter(function() {             var text = $(this).text().replace(/\s+/g, ' ').tolowercase();             return !~text.indexof(val);         }).hide();     });     $('#filtersearch').keyup(); }); 

in order limit search, need limit selector $rows. example, if want apply filterable class cells in individual columns , search columns adjust $rows declaration this:

var $rows = $('#orders tbody .filterable'); 

and if want hide rows based on results, need find parent row td.filterable hide, need adjust hide line of code find closest tr this:

       $rows.closest('tr').show().end().filter(function() {             var text = $(this).text().replace(/\s+/g, ' ').tolowercase();             return !~text.indexof(val);         }).closest('tr').hide(); 

though in doing so, might want change name of variable since no longer tied "rows". kept variable name same here can see changes in code needed make work.


Comments