Thursday, 22 August 2013

Search in HTML-table - Combine multiple values (dropdown, textfield ..)

Search in HTML-table - Combine multiple values (dropdown, textfield ..)

Is it possible to add a dropdown-menu to the form, and that the function
will combine the selected value from the dropdown and the value of the
textfield to search?
The code is applied on a HTML table, so that the visitor can search in the
table.
Thanks! :)
<script type="text/javascript">
function search (phrase, _id){
var words = phrase.value.toLowerCase().split(" ");
var table = document.getElementById(_id);
var ele;
for (var r = 0; 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;
}
}
</script>
<form>
<b>Words:</b>
<input name="filter" onkeyup="search(this, 'my-table', 1)" type="text">
</form>

No comments:

Post a Comment