Insert option no select multiple dynamically

1

Good morning !!!

I need that when typing a process number and clicking on the magnifying glass, the process will go to the select multiple box, as shown in the attached image. However I need this process several times and go populate the select multiple and then click on the select button and these selected values appear in a text box on the main screen, because this box is a modal. Hj I can only insert a process, if I look for another process and click on the magnifying glass, it replaces what is already in the box, instead of adding.

Thank you.

    
asked by anonymous 10.10.2016 / 15:29

1 answer

0

We can put a code that will add the values of input into select by clicking on the magnifying glass, and then doing something with the content. The code looks like this:

$("#vai").click(function() {
  var processo_val = $("#processo").val();
  $("#select").append(
    $("<option/>")
    .val(processo_val)
    .text(processo_val)
  );
  $("#processo").val("").focus();
});

$("#ok").click(function() {
  var processos = [];
  $("#select option").each(function(idx, el) {
    processos.push($(el).val());
  });
  alert(JSON.stringify(processos));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><strong>Processo:</strong><inputid="processo" type="text"> <button id="vai">adicionar!</button><br><br>
<select id="select" multiple style="width: 200px;">
</select>

<hr>

<button id="ok" style="font-size:16pt;">Clique aqui para fazer algo com os processos!</button>
    
11.10.2016 / 22:42