Playing dice for a box

1

I need to get data from an input and move to a box!  I have a cod that takes the data of a combo to play in a box!

cod:

function move(Origem, Destino)
{
    var opt = document.createElement("option"); 

    for(i = 0; i < Origem.options.length; i++)
    {
        if (Origem.options[i].selected && Origem.options[i].value != "")
        {
            if(w_seq_qtde[Origem.options[i].value]==0)
                alert("sem periférico no estoque!");
            else
            {
                document.getElementById("cb_MenuDestino").options.add(opt);
                opt.text = Origem.options[i].text;
                opt.value = Origem.options[i].value;
                w_seq_qtde[Origem.options[i].value]--;
            }
        }
    }
}

input:

<input type="text" name="tx_MenuOrigem" value="">

button:

<input type="button" onClick="move(this.form.tx_MenuOrigem,this.form.cb_MenuDestino)" value="+++">

select:

<select multiple size="7" name="cb_MenuDestino" style="width:300"></select>

In this case when you select the item in the combo and press on a button to add it plays in the box! But I want to get the data in an input and play inside the box! If possible, how can it be more or less similar to a better understanding ?! Thanks to those who help!

    
asked by anonymous 11.08.2014 / 15:48

2 answers

1
function move(input, Destino)
{
 var opt = document.createElement("option"); 
 var valor = input.value;
 if(valor=="")
 return;

  if(valor==0)
  { 
    alert("sem periférico no estoque!"); 
   return;
  }            

  opt.text = valor ;
  opt.value = valor ;
  Destino.options.add(opt);

 }
    
11.08.2014 / 16:08
1

Verify that the value already exists

function JaExiste(Destino, valor)
{

for(i = 0; i < Destino.options.length; i++)
    {
        if (Destino.options[i].value == valor)
                   return true;
     }
return false;
}

Add value in select

function move(input, Destino)
{
//Obtém o valor digitado 
 var valor = input.value;

 //retorna se não houver valor ou se o valor já existir no destino

 if(valor==""|| JaExiste(Destino,valor)) return;

//Mensagem do explo caso o valor seja 0
  if(valor==0)
  { 
    alert("sem periférico no estoque!"); 
   return;
  }        
  var opt = document.createElement("option"); 
  opt.text = valor ;
  opt.value = valor ;
  Destino.options.add(opt);
 }
    
11.08.2014 / 17:36