Can you please help me code Jquery right way so i can filter HTML table based on text input. So far this is my code:
<input type="text" name="inputdata" id="inputdata" onkeyup="filter()">
<table>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
<tr name="data">
<?php foreach ($products as $row) { ?>
<td><?php echo $row->id_product; ?></td>
<td><?php echo $row->name; ?></td>
<?php } ?>
</tr>
Jquery code
<script>
function filter(){
inp = $('#inputdata').val()
$("tr").filter(function() {
return $(this).text().indexOf(inp) == -1;
}).hide();
}
</script>
So my problems are:
- Search is case sensitive
- When i input some string, let's say Pants, Jquery filters data, but then i have to refresh a page, so i can search again. Or let me put this other way... When i delete inputted data in search field, table isn't refreshed. It just stay on Pants data, so for another search i have to reload web page
<th>are removed when searching for data. If i declare$('tr[name=data]').filter(function() {search stop working
thx in advance for helping me!