javascript - How to let the current type status of the customer show in the drop-down menu -


here select box/drop-down menu:

 var type_select = '<select id="type_select" style="margin-bottom:0px;">';           var i;           var customer_group = <?php echo json_encode($customer_group);?>;           (i = 0; < customer_group.length; ++i) {             //console.log(customer_group[i].group_id);             if (customer_group[i].group_name == table_column_3){               type_select = type_select+'<option value='+customer_group[i].group_id+' selected="selected">'+customer_group[i].group_name+'</option>';             }else{               type_select = type_select+'<option value='+customer_group[i].group_id+'>'+customer_group[i].group_name+'</option>';             }           }           type_select = type_select+'</select>'; 

modal dialog box:

 bootbox.dialog({             onescape:true,             backdrop:true,           message: '<div class="row">  ' +                    '<div class="col-md-12"> ' +                    '<form class="form-horizontal"> ' +                    '<div class="form-group"> ' +                    '<label class="col-md-4 control-label" for="awesomeness">phone: </label> ' +                    '<div class="col-md-4">' +                    '<input id="edit-phone_no" type="text" value="'+table_column_7+'"/>' +                    '</div><br>' +                    '<label class="col-md-4 control-label" for="awesomeness">name: </label> ' +                    '<div class="col-md-4">' +                    '<input id="edit-name" type="text" value="'+table_column_2+'"/>' +                    '</div><br>' +                    '<label class="col-md-4 control-label" for="awesomeness">type: </label> ' +                    '<div class="col-md-4">' +type_select+ '</div>'+                    '</form> </div>  </div>'}); 

javascript/ajax function show name , type of customer automatically when enter phone number

document.getelementbyid('edit-phone_no').onkeyup = function(){      text_length = $('#edit-phone_no').val().length;      if (text_length >= 8){       $.ajax({                  url : "<?php echo base_url(); ?>index.php/home/get_name_by_phone_no",                  type: "post",                  data: {                      "phone_no" : $('#edit-phone_no').val(),                  },                  success: function(response){                   console.log(response);                   var data = json.parse(response);                     if (response != ""){                      $('#edit-name').val(data.name);                      $('#type_select').val(data.group_name);                      }                  }              });      } } 

php function name , type(group_name) of customer database based on phone number:

public function get_name_by_phone_no($phone_no){         $result = "";         $this->db->select('name,group_id');         $this->db->where('phone_no',$phone_no);         $query = $this->db->get('customer');         if ($query->num_rows() > 0){         $row = $query->row();         $group_id = $row->group_id;         $row->group_name = $this->get_group_name_by_group_id($group_id);         $result = $row;         }         echo json_encode($result);      } 

when enter phone no. of customer, name automatically shown in textbox , type of customer automatically selected in drop-down menu(all based on records in database).the name part works type part not work. there must problem. please tell me how fix it. thank of in advance.

error in logic. when creating select box(drop down menu) setting option value group_id , side returning group name:

   $row->group_name = $this->get_group_name_by_group_id($group_id) 

group name server in ajax call.

so mistake ajax response has group name when options value in id so

  $('#type_select').val(data.group_name); 

data.group_name not match value in option not working.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -