0
I made an interface where the user type a number and it is soon assigned to a value of select. The idea is that the user type a number and cannot type it again, but for this, I need that in each function call, a list of values present in the select, and I’m not getting it.
The Javascript code I tried and so far has not worked:
function validarNumero() {
let numeroInput = Number(document.getElementById('inNumero').value)
let tabela = document.getElementById('numerosAnotados')
let numeros = Array.from(tabela)
if (numeros.indexOf(numeroInput) == -1) { // -1 == Não tem
numeros.push(numeroInput) // Criando um registro
let item = document.createElement('option')
item.text = numeroInput
tabela.appendChild(item)
}
}
<section>
<div>
<p>Digite um numero [1 - 100]: <input type="number" name="" id="inNumero">
<input type="button" value="Adicionar" onclick="validarNumero()"></p>
</div>
<div>
<p><select id="numerosAnotados" size="10"></select><br>
<input type="button" value="excluir" onclick="excluir()">
</p>
</div>
</section>