There is a table and a text input box on the HTML page. Whenever the user types a value in the box, the Javascript should filter the table and show only the rows which has the value in the data.
I have done with this part but the main problem is if the user types space in the box and then types another value then the js should filter the data where all of the words (text separated with space) are present at least once in any cell of the row, just like Google Suggestions but with table.
Does anyone have a solution?
HERES THE CODE
for(var i=0; i < trs.length; i++ )
{
tds = trs[i].getElementsByTagName("td");
//alert(tds );
for( var j=0; j < tds.length; j++ )
{
if( hasWords )
{
for( k = 0; k < searchWords.length; k++ )
{
if( searchWords[k].toLowerCase() != "" && tds[j].innerHTML.toLowerCase().search( searchWords[k].toLowerCase() ) == -1 )
{
found = false;
//foundRows.push(trs[i]);
}
else {
found = true;
foundRows.push(trs[i]);
}
}
}
else
{
if( searchText != "" && tds[j].innerHTML.toLowerCase().search( searchText.toLowerCase() ) != -1 )
{
found = true;
foundRows.push(trs[i]);
}
}
/*
if( tds[j].innerHTML.toLowerCase().search( searchText ) != -1 )
{
found = true;
foundRows.push(trs[i]);
}
*/
}
}