Change dropdown jquery filter to individual checkboxes

394 views Asked by At

I need help making this code

<select id="fruit" class="friltro">
  <option value="all">All fruits</option>
  <option value="apple">apple</option>
  <option value="orange">orange</option>
  <option value="pineapple">pineapple</option>
  </select>
  <select id="price" class="friltro">
  <option value="all">All prices</option>
  <option value="1">$1</option>
  <option value="3">$3</option>
  <option valenter code hereue="4">$4</option>
</select>

into individual check boxes this is what I have so far

<input type="checkbox" id="price" value="all" class="filtro" >
<label for="filtro" >all</label>
<input type="checkbox" id="apple" value="apple" class="filtro" >
<label for="filtro" >apple</label>

but it does not work at all the drop down does, but when I try to make into a checkboxes it stops working.

also here is the jquery code

$('.friltro').change(function () {
var criteria = '';
var showAll = true;
$('.friltro').each(function () {
    var val = $(this).children(':selected').val();
    if (val !== 'all') {
        criteria += '.' + $(this).attr('id') + '-' + val;
        showAll = false;
    }
});
if (showAll) {
    $('.item').show();
} else {
    $('.item').hide();
    $(criteria).show();
}

});​

also here is what I am trying to filter

 <div class="item apple 1>

Apple $1


</div>
<div class="item orange 4">

An orange that costs 4 dollars
</div>

The stuff being filtered is very simple I know but once the script works, I will be adding images css. Can anyone help?

0

There are 0 answers