How to make a dynamic select?

0

I'm making a restaurant sisteminha, and it's a command. But, like, you have select of food orders, but I wanted to know how I can do when I click on the + sign to show another select under what already has to order the other food, because not always the customer wants only one thing.

I'm doing the system with PHP and JavaScript.

    
asked by anonymous 15.01.2017 / 16:52

1 answer

4

Would that be it? Instead of selecting another select, I made an example that when selecting adds an input with the value that was added.

$(".add").on('click',function(){
var cont=0;
$("#selecionados input").each(function(){
if($(this).val()==$("#selecionar option:selected").html()){
cont++;
 }
});
if(cont>0){ alert("Este item ja esta adicionado, altere a quantidade se deseja mais..");}
else{
$("#selecionados").append("<input disabled type='text' name='pedidos[]' value='"+$("#selecionar option:selected").html()+"' ><input type='text' name='quantidade[]' placeholder='quantidade'><br>");
}
});
.add{ text-decoration:none;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><selectid="selecionar">
<option selected isabled>Selecione</option>
<option>Pao</option>
<option>Leite</option>
<option>Cafe</option>
</select>
<a class="add" href="#">+</a>
<hr>
Selecionados
<hr>
<div id="selecionados">
  
</div>

And in php you would get the value in array, like this:

<?php $valores=$_POST['pedidos'] 
foreach($valores as $item){
echo $item."<br>";
}


?>
    
15.01.2017 / 17:20