I have form containing multiple checkboxes and I want that checkboxes to be checked according to their values from database using jquery after clicking edit button? Thanks in advance..
Here is view:
<form id="frmAddBand" name="frmAddBand" method="post" action="" onsubmit="return (checkc() == 1)">
            <fieldset>
                <ol>
                     <li>
                        <label >Band Code <em>*</em></label>
                        <input id="bandCode" type="text" name="bandCode"  />
                        <span id="code_status" style="color:red;" ></span>  
                  </li>
                  <li>
                        <label >Band Name<em>*</em></label>
                        <input id="bandName" type="text" name="bandName" />
                  </li>
                  <li>
                        <label >Designation<em>*</em></label><br/><br/><div style="height:100px;background-color:#fff;overflow:auto;"><br/><?php $des_code = array_keys($designation);
                              $des_name = array_values($designation);
                             for($i=0;$i<count($des_code);$i++){?>
                        <input type="checkbox"  name="des" id="des" value="<?php echo $des_code[$i];?>"/><span style="font-size:12px;"><?php echo $des_name[$i];?></span><br/><br/><?php }?>
                        </div>
                  </li>
                                            <li class="required new">
                                            <input type="text" id="demo" name="demo" />
                        <em>*</em> Required field                        </li>
                                        </ol>    
                                    <p><input id="click_submit" name="click_submit" Value="Save" type="button">
                   <input id="click_cancel" name="click_cancel" Value="Cancel"  type="button" >                 
                </p>
            </fieldset>
        </form>
controller:
public function band_edit($id)
            {
            $this->load->helper('url');
            $this->load->database();
            $this->load->model('Ohs_Bandmodel');
            $data = $this->Ohs_Bandmodel->get_by_id($id );
                echo json_encode($data);
            }
script:
function edit_band(id)
                    {
                        $("#frmAddBand")[0].reset();
                        //Ajax Load data from ajax
                     $.ajax({
                            url : "<?php echo base_url(); ?>index.php/Ohs_Cband/band_edit/" + id,
                            type: "GET",
                            dataType: "JSON",
                            success: function(data)
                            {
                     var b=data.desig;
                     var arr = b.split(",");
                    //alert(arr[1]);
                                for(i=0;i<arr.length;i++){
                                    $('input[type=checkbox]').each(function(){
                                        //alert(arr[i]);
                                        if($(this).val()==arr[i]){
                                $(this).prop('checked', true);
                                }
                                else{
                                    $(this).prop('checked', false);
                                }
                                })
                                }
                                $('[name="bandCode"]').val(data.band_code);
                                $('[name="bandName"]').val(data.band_name);
                                $('[name="click_submit"]').val('Update');
                                $('[name="bandCode"]').attr("readonly", true);
                                $('[name="bandCode"]').css('background-color' , '#DEDEDE');
                                //$("#click_cancel").attr('visibility', 'visible');  
                                $('#click_cancel').show();
                            },
                            error: function ()
                            {
                                //alert('Error get data from ajax');
                                $('[name="bandCode"]').attr("readonly", false);
                                $('[name="bandCode"]').css('background-color' , '#FFF');
                                $('[name="bandCode"]').removeAttr("disabled"); 
                                $("#Notify").data("mtype","E");
                                $("#Notify").data("msg","error in record.")
                                $('#Notify').trigger('click');
                                //$("#click_cancel").attr('visibility', 'hidden');   
                            }
                        });
                    }
when I click on edit record all works fine but instead of checking 2 checkbox based on data in records it checks only 1 checkbox.Any help would be appreciated.Thanks
 
     
     
    