Click here to Skip to main content
15,743,429 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I am trying to get records using checkbox Filters, like.

If green check box is checked then only green colors product will show.

I somehow get the checkbox data using ajax in an array but now I am just blocked that how to pass it to the model, because the data is in an array from and i have to use the where condition. So my issue is that how to pass that array in where condition to match it with the columns and get the record accordingly.

The array data looks like in console:

Console data

Product Table:

Product Table

Product_attributes Table:

Product Attributes Table

What I have tried:

My View Code

<pre><!-- Color -->
              <div class="widget filter-by-color">
                <h3 class="widget-title heading uppercase relative bottom-line full-grey">Color</h3>
                <ul class="color-select list-dividers">
                      <input type="checkbox" class="input-checkbox" id="green-color" name="color" value="g" onchange="clr();">
                    <label for="green-color" class="checkbox-label">Green</label>
                      <input type="checkbox" class="input-checkbox" id="red-color" name="color" value="r" onchange="clr();">
                    <label for="red-color" class="checkbox-label">Red</label>
                      <input type="checkbox" class="input-checkbox" id="blue-color" name="color" value="bl" onchange="clr();">
                    <label for="blue-color" class="checkbox-label">Blue</label>
                    <input type="checkbox" class="input-checkbox" id="white-color" name="color" value="w" onchange="clr();">
                    <label for="white-color" class="checkbox-label">White</label>
                    <input type="checkbox" class="input-checkbox" id="black-color" name="color" value="b" onchange="clr();">
                    <label for="black-color" class="checkbox-label">Black</label>

My Js Code

<pre>function clr(){
           var selected = new Array();
           var url="<?php echo base_url('Cart/filt');?>";
          // alert(url);
              $("input:checkbox[name=color]:checked").each(function() {

My Controller Code:

<pre> function filt()
        echo json_encode($colors);

Please Share Your Logic, Thoughts, Links, Info...

Any help will be highly appreciated.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900