Spring mvc bootstrap

0

asked by anonymous 19.05.2017 / 03:37

1 answer

0

Your question is answered with an implementation in JQuery and an HTML post for Spring MVC to handle your choices, but it is not really related to Spring MVC or Bootstrap.

Now, once your select is loaded with the required fields, and an "Add" button next to it, the chosen value will be sent to an empty form , which, when submitted, sends the chosen codes to the page responsible for treating them. In addition it is clear to visually insert on the screen to the user as feedback and remove them from select .

<p>Para onde você quer ir?</p>
<select id="meu_select">
  <option value="1">Paris</option>
  <option value="2">Moscou</option>
  <option value="3">Roma</option>
  <option value="4">Viena</option>
</select>
<button onclick="minha_funcao();">Adicionar</button>

<p>Você já escolheu:</p>
<div id="escolhas">
  <!-- Inicialmente vazio! -->
</div>

<form id="meu_form" method="post" action="/pagina_responsavel.php">
  <input type="submit" value="Submeter escolhas">
</form>

<script>
function minha_funcao() {
  if($('#meu_select').val()) {
    // Adiciona no post uma variável que tem nome criado a partir do 
    // valor escolhido (id_...) e o valor escolhido
    $('#meu_form').append('<input type="hidden" name="id_' + 
      $('#meu_select').val() + '" value="' + $('#meu_select').val() + '">');

    // Adiciona na tela o valor escolhido
    $("#escolhas").append("<p>" + $('#meu_select option:selected').text() + "</p>");

    // Remove do select o valor escolhido
    $("#meu_select option[value=\""+$('#meu_select').val()+"\"]").remove();
  }
}

</script>

The easiest way to know which value (s) has been chosen is to check that for every value sent to select there is a variable of post id_value , where value is 1 , 2, 3, 4, etc.

    
21.06.2017 / 20:09