1

I have this JQuery Script that will supposedly look for each letters (or names of the Client from the List of Clients table) typed by the user on the searchbox.

<script>
$(document).ready(function() {
    $("#search-value").on("keyup", function() {
        var value = $(this).val();
        $("table tr").each(function(index) {
            if (index!==0) {
                $x = $(this);
                var id = $x.find("td:first").text();
                if (id.indexOf(value)!==0) {
                    $x.hide();
                }
                else {
                    $x.show();
                }
            }
        });
    });
});
</script>

But the thing is, it only works for numbers, commonly IDs if the user searched for the clients' ID numbers instead. What I want is to make it work also, not just for IDs but the letters or preferable names typed by the users. BTW, this is just a follow up question of In-Page Result Search This is also similar to a JQuery Script given by one of this site's Q&A. And it seems to work fine either by letters or numbers. So I wonder what would be the problem when I installed it on my index page?

Community
  • 1
  • 1
Archangel08
  • 91
  • 10
  • what if you change to ``.each(function(index, value)`` and ``if(value!="" || index!==0){}`` instead of ``if(index!==0)`` ? – doniyor Aug 11 '14 at 02:21
  • Why isn't it working. Can you give sample data? I'm not seeing an issue with a table I just created. – drneel Aug 11 '14 at 02:23
  • @doniyor I did your advice, changing .each(function(index, value) and if(value!="" || index!==0){} instead of if(index!==0). But just like the previous, it only works for client's ID and not for their searched names. – Archangel08 Aug 11 '14 at 02:47
  • @drneel, yes there's no issue if we tried the jsfiddle. but when I installed it on my index.php, the search only triggers for IDs (if the user typed the Client ID numbers. Yet, once you searched for the Client's name, it only shows blank results.) – Archangel08 Aug 11 '14 at 02:51

0 Answers0