I'm trying to check if all the input fields are filled in this form, the inputs are created based on the number of players, so I dynamically created them in JavaScript, how can I do that ? Here is what I tried
const x = localStorage.getItem('playersNum');
for (let i = 0; i < x; i++) {
const newInput = document.createElement("INPUT");
newInput.setAttribute("type", "text");
newInput.setAttribute("class", "form-control");
newInput.setAttribute("id", `player${i}`);
newInput.setAttribute("placeholder", "Player's Name");
const parentDiv = document.getElementById('player-list');
parentDiv.appendChild(newInput);
const input = document.getElementById(`player${i}`);
const btn = document.getElementById('startGame');
btn.addEventListener('click', function() {
if (input === "") {
alert('Please fill in the players names');
}
});
}