0

This is what i am trying to get as result.

$(document).ready(function() {
  $('.i_filter').change(function(e) {
    e.preventDefault();

    $('.i_filter:checked').each(function() {

      var ele = [];
      ele = $(this).val();

      if ($('.i_filter').is(':checked')) {
        jQuery.ajax({
          url: 'filter_product.php',
          type: 'POST',
          data: {
            ele: ele
          },
          success: function(data) {
            $("#filter_result").html(data);
          }
        });
      } else {
        alert('Hello');
        jQuery.ajax({
          url: 'allproduct.php',
          type: 'POST',
          data: {},
          success: function(data) {
            $("#filter_result").html(data);
          }
        });
      }
    });
  });
});

I want some data when check box is checked and after unchecked all the check boxes all data will be display in the div.

This system i want for creating shopping site filter using checkbox.

0

2 Answers 2

0

Try this out. Something which i used for my case.

$('.business-type  input:checkbox').click(function(){
   businessTypeValue=$('.business-type  input:checkbox').map(function(n){
     if(this.checked){
        return  this.value;
      };
   }).get().join(',');
})
Sign up to request clarification or add additional context in comments.

Comments

0

It's simple php code ..

// html page ..

<label>Select State</label><br>
<?php 
$allgroup = mysql_query("SELECT * FROM  state");
$flag=false;
while($state_list = mysql_fetch_array($allgroup))
{
   $parr=explode(',',$er['state_id']);
   $size = sizeof($parr);
   for($i=0;$i<$size;$i++) { 
     if($parr[$i]==$state_list['id']) {                              
        $flag=true;
     } 
   }    

  if($flag==true) {
    ?>
    <input  type='checkbox' name='state[]' style="margin-left:5px;" value="<?php echo $state_list['id']; ?>" checked  > <?php echo $state_list['name']; ?> <br>
    <?php
    $flag=false;
  } else { 
    ?>
    <input  type='checkbox' name='state[]' style="margin-left:5px;" value="<?php echo $state_list['id']; ?>"     > <?php echo $state_list['name']; ?> <br>
    <?php
    }
}
?>

// php code ...

<?php
$states="";
$i=0;
foreach( $_POST['state'] as $selected) {
   echo sizeof($_POST['state']);
   if($i==sizeof($_POST['state'])-1) {
       $states = $states.$selected;
   } else {
     $states = $states.$selected.",";
   }
   $i++;
}
?>

1 Comment

I don't want for php. I want this for jQuery. How to check the checkbox is checked or unchecked.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.