I have the following code for a multi select list. It works when one item is selected at a time. I want to make it work when I select more than item.
<select name="size1" multiple="multiple" id="ddYear"
class="form-control input-sm">
<option value="">Select Manufacturers</option>
<?php
$record = mysqli_query($con
"SELECT DISTINCT Manufacturer
FROM db
WHERE Manufacturer in ('A', 'B', 'C', 'D', 'E', 'F')
ORDER BY Manufacturer ASC");
while ($row = mysqli_fetch_array($record)) {
echo "<option value='" . $row['Manufacturer'] . "'>"
. $row['Manufacturer'] . "</option>";
}
?>
</select>
Js code
<script type="text/javascript">
var $rows = $('#dataTables-example2 tbody tr');
$('#ddYear').change(function() {
var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();
$rows.show().filter(function() {
var text = $(this).text().replace(/\s+/g, ' ').toLowerCase();
return !~text.indexOf(val);
}).hide();
});
</script>
It works with one item selected (the matching table rows are shown), but when I select two items, it hides all rows from my table (nothing matches). Instead I would like to see the rows that match with one of the selected items.