I have a forEach
loop for an array but with an if statement to check if the input is empty. The problem is that the loop stops if it finds an empty input i want it to check all the element in the array even if 1 is empty
here is my code
function showError(input, message) {
const formControl = input.parentElement;
formControl.className = "form-control error";
const small = formControl.document.querySelector("small");
small.inerText = message;
}
//show success message
function showSuccess(input) {
const formControl = input.parentElement;
formControl.className = "form-control success";
}
//check requiered fields
function checkRequired(inputArr) {
inputArr.forEach(function(input) {
if (input.value.trim() === "") {
showError(input, "is required");
} else {
showSuccess(input);
}
});
}
// Event listener
form.addEventListener("submit", function(e) {
e.preventDefault();
checkRequired([username, email, password, password2]);
});