-2
Hello! In my code, I have 12 inputs. When I click on a given button, I need to check which of these inputs has something written and save that value in a single array. What I’m not able to do is store all these values in a single array. HTML:
<div class="inputsParticipantes">
<h3>Quais são os nomes dos participantes ?</h3>
<input type="text" class="inputPlayers">
<input type="text" class="inputPlayers">
<input type="text" class="inputPlayers">
<input type="text" class="inputPlayers">
<input type="text" class="inputPlayers">
<input type="text" class="inputPlayers">
<input type="text" class="inputPlayers">
<input type="text" class="inputPlayers">
<input type="text" class="inputPlayers">
<input type="text" class="inputPlayers">
<input type="text" class="inputPlayers">
<input type="text" class="inputPlayers">
<button class="comecar btn">Começar</button>
</div>
Javascript:
var $players = document.querySelectorAll('.inputPlayers');
var $comecar = document.querySelector('.comecar');
$comecar.addEventListener('click', jogar)
function jogar(){
var x = 0;
while($players[x]){
if($players[x].value.length >= 1){
guardarValorInputs($players[x])
}
x++;
}
function guardarValorInputs(inputs){
var valor = inputs.value;
var arrValorInput = valor.split();
console.log(arrValorInput);
}
Why the
x++
doesn’t get drained ofwhile
?– Woss
But he’s inside the while
– Leandro