Roll dice into a box

Asked

Viewed 85 times

1

I need to take the data of an input and pass to a box! I have a Cod that takes the dice from 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 selecting the item in the combo and pressing on a button to add it plays in the box! But I want to take the dice in an input and play inside the box! If possible has to be more or less similar for better understanding?! Thanks to those who help!

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);

 }
  • I want to block if the data is the same as entered, as I do?

  • Can you explain how your answer solves the problem?

  • Function Jaexiste(Destination, value) { for(i = 0; i < Destination.options.length; i++) { if (Destination.options[i].value == value) Return true; } Return false; } &#Function moves(input, Destination) { var opt = Document.createelement("option"); var value = input.value; if(value==""|| Jaexiste(Destination,value)) Return; if(value==0) { Alert("without peripheral in stock!"); turn; } opt.text = value; opt.value = value ; Target.options.add(opt); }

1

Check if 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);
 }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.