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

Here is the 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);?>;
          for (i = 0; i < 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 to show name and 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 to get name and type(group_name) of customer from 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 I enter the phone no. of a customer, I would like the name to be automatically shown in the textbox and the type of customer to be automatically selected in the drop-down menu(All based on the records in the database).The name part works now but the type part does not work. There must be a problem. Please tell me how to fix it. Thank you very much all of you for your help in advance.

Answer:1

error in your logic. when you are creating SELECT box(drop down menu) you are setting option value as group_id and another side you are returning group name:

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

group name from server in ajax call.

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

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

data.group_name does not match with any value in option so it is not working.

Answer:2

Is it possible to style the hyperlink tag in CSS in such a way that when a link is clicked it opens it in a new tab or window? I know the solution in HTML and JavaScript/jQuery, yet is it possible to ...

Is it possible to style the hyperlink tag in CSS in such a way that when a link is clicked it opens it in a new tab or window? I know the solution in HTML and JavaScript/jQuery, yet is it possible to ...

  1. open links tabs
  2. links opentable click
  3. open links in tabs instead of new windows
  4. open links new tab chrome
  5. open links in tabs firefox
  6. open links new tab html
  7. open links in tabs chrome
  8. open links new tab firefox
  9. open links in tabs chrome extension
  10. open links same tab
  11. html open link tab
  12. open links in tab google
  13. open links in new tab
  14. open links in new tab chrome default
  15. open links in same tab chrome
  16. open links in new tab wordpress
  17. open links in new tab css
  18. open links in new tab chrome extension
  19. open links in new tab safari
  20. open links in new tab internet explorer

I am trying to learn JavaScript from a book. The first chapter of the book says to use the following format to support older browsers that don't support JS. What it actually does is simple, it uses ...

I am trying to learn JavaScript from a book. The first chapter of the book says to use the following format to support older browsers that don't support JS. What it actually does is simple, it uses ...

  1. hiding javascript from incompatible browsers
  2. hiding javascript from view source
  3. hiding javascript from old browsers
  4. hiding javascript in image
  5. hiding javascript in html
  6. hiding in javascript
  7. javascript hidden element from table

I am trying to understand what's the thing with javascript Objects while using them as an associative array. From ECMA: 4.3.3 An object is a member of the type Object. It is an unordered ...

I am trying to understand what's the thing with javascript Objects while using them as an associative array. From ECMA: 4.3.3 An object is a member of the type Object. It is an unordered ...

  1. object property order javascript
  2. object property order
  3. object property order js
  4. json object property order
  5. powershell object property order
  6. es2015 object property order
  7. es6 object property order
  8. new-object property order
  9. php object property order
  10. c# object property order
  11. object.keys property order

Given the following file app.js $stateProvider .state('intro', { url: '/intro', templateUrl: 'partials/intro.html', controller: 'IntroController as IntroCtrl' }) ...

Given the following file app.js $stateProvider .state('intro', { url: '/intro', templateUrl: 'partials/intro.html', controller: 'IntroController as IntroCtrl' }) ...