Embed combobox with data from the base in ajax

0

Hello good morning I have an ajax that what it does is load questions in an accordion I have a field which is an input text that I write some data in the database and it sends me the info according to whether it is embedded but now what I want to change it to a combobox so that people can see who is there and not have to write always in the input text could help me how to do it so that I can show them in a combobox

    
asked by PlayTutoAlvarez 20.09.2018 в 15:56
source

1 answer

0

When I finished the route of the collected data, I would create another function by passing the data to it and point to the txt_tec_ins_inc element. I do not know if this example is useful for you. If you get more select in the creation, I would go through it the DOM selecting all the selections inside that container. I hope it helps you.

$(document).ready(function(){
var datos = ["peter","antonio","juan","Andrés","Javi"];

function rellenaCampos(datos){
    $.each(datos,function(i,e){
     $("#txt_tec_ins_inc").append('<option value="'+ e +'">'+ e +'</option>');
     
    })
   
   };
   
  function rellenarSelects(){
   
      $("#caja").append('<select class="form-control" id="txt_tec_ins_inc"></select>');
   
    rellenaCampos(datos);
  };
  rellenarSelects();
});
div{
margin-left:200px;
}

#txt_tec_ins_inc{
width:200px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet"/>

<div id="caja"></div>
    
answered by 04.01.2019 в 14:21