<script type="text/javascript">
$("#state_id_add").select2({
  placeholder: "Select State Code",
  dropdownParent: $("#form_customer_add")
})
$("#state_id_edit").select2({
  placeholder: "Select State Code",
  dropdownParent: $("#form_customer_edit")
})

$("#sale_price_category_add").select2({
  placeholder: "Select Sale Price",
  dropdownParent: $("#form_customer_add")
})
$("#sale_price_category_edit").select2({
  placeholder: "Select Sale Price",
  dropdownParent: $("#form_customer_edit")
})
function select_customers(select_id,type='',selected_value=''){
  $('#'+select_id).html('');
  if(type=='filter'){
    $("#"+select_id).append("<option value='all' selected >All Customers</option>");
  }else{
    $("#"+select_id).append("<option disabled selected >Select Customer</option>");
  }
  $.post("<?php echo base_url() ?>customers/select_customers_2"
  ,function(data) {
    var obj = $.parseJSON(data);
    var i=0;
    if(obj.count>0) {
      while (i < obj.id.length) {
        $("#"+select_id).append("<option value='" + obj.id[i] + "' data-contact-person='"+obj.contact_person[i]+"' data-phone='" + obj.phone[i] + "'>" + obj.name[i] +" ("+obj.contact_person[i]+") ["+obj.phone[i]+"]"+ "</option>");
        i++;
      }
      if(selected_value!=''){
        $("#"+select_id).val(selected_value).trigger("change");
      }
    }
  })
}


</script>
