-2

I can't turn searchBox to a .toLowerCase and my code is case sensitive because of this. I want the code to scan on both upperCase and lowerCase letters.

I wasn't able to find a solution to my problem.

<script>
$("#searchBtn").keyup(function () {
    var searchBox = $("#searchBtn").val();

    var returnRows = [];

    $('tr').not('.headerRow').each(function () {
        var addRow = true;
        var $currentRow = $(this);

        $currentRow.find('td').each(function () {
            var $td = $(this);
            var word = $td.text();

            if (word.indexOf(searchBox) > -1) {
                addRow = false;
                return false;
                // console.log("KOMT IN IF STATEMENT");     //sla deze rij op in een tijdelijke array
            }
        });

        if (addRow) {
            returnRows.push($currentRow)
        }
    });

    if (true)
    {
        $('tr').show();
    }

    $.each(returnRows, function (i, v) {
         $(v).hide();
    });
});
</script>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Lloyd
  • 1,119
  • 10
  • 29

1 Answers1

1

I am not sure but you are making it a bit more complicated. Try something like this:

$("#searchBtn").keyup(function() {
  var word = $("#searchBtn").val(), 
      timer;

  if(timer){ clearTimeout(timer); }

  timer = setTimeout(function(){
     $('tr').not('.headerRow').filter(function(){
        var txt = $(this).find('td').text();
        return txt.indexOf(word) !== -1 && txt === word;
     }).hide();
  },900);

});

=== lets you compare strictly. So, in such case T !== t would result in true.

Jai
  • 74,255
  • 12
  • 74
  • 103