[JS - Snippet] Filter table

1 post Page 1 of 1
Contributors
Filip
Coding Guru
Coding Guru
Posts: 833
Joined: Wed Jan 05, 2011 3:59 pm

[JS - Snippet] Filter table
Filip
Hello,

This code snippet is going to filter table (read: hide rows which don't match the text). Just attach event to some element and call function
Code: Select all
function filter (phrase, _id){
	var words = phrase.value.toLowerCase().split(",");
	var table = document.getElementById(_id);
	var ele;
	for (var r = 1; r < table.rows.length; r++){
		ele = table.rows[r].innerHTML.replace(/<[^>]+>/g,"");
	        var displayStyle = 'none';
	        for (var i = 0; i < words.length; i++) {
		    if (ele.toLowerCase().indexOf(words[i])>=0)
			displayStyle = '';
		    else {
			displayStyle = 'none';
			break;
		    }
	        }
		table.rows[r].style.display = displayStyle;
}
}
CodenStuff wrote:
Nope, it's just your sick and dirty mind. You sick twisted warped little pervo :D
1 post Page 1 of 1
Return to “Tutorials”