Reputation: 33
I have a searchbox as below:
<input type="text" class="form-control" onkeyup="myFunction()" id="myInput"/>
and I have a table with id="show_member" with different columns. I have written a code as below and I would like to search all columns whenever I type something in the searchbox(the input above) What is the problem with the code and how can I fix it? Not only doesn't it show the related columns but also it doesn't get removed when I delete all the letters in the search box.
function myFunction(){
var input = document.getElementById("myInput");
//alert(input.value);
var iv = input.value;
var rows = $('table tr').hide().filter(":contains(".'iv'.")").show();
}
thanks for your help in advance
Upvotes: 0
Views: 770
Reputation: 133403
Use +
for string operators(concatenation) in JavaScript
$('table tr').hide().filter(":contains(" + iv +")").show();
instead of
$('table tr').hide().filter(":contains(".'iv'.")").show()
Upvotes: 4