I am still a beginner. I am validating a form and I want the errors that the user makes to be shown in a list generated by a for . The problem arises in the for part, because when I do console.log, you see that it shows me 17 times the same error generated, besides that when I press send again, it retraces its 17 times . Thanks
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<style>
.error{
border: 2px solid red;
}
.success{
border: 2px solid green;
}
</style>
</head>
<body>
<form action="">
<div><input type="text" id="name" placeholder="Tu nombre" ></div>
<div><input type="text" id="edad" placeholder="Tu edad" ></div>
<div><input type="number" id="numero" placeholder="Tu numero"></div>
<div><input type="email" id="email" placeholder="Tu email" ></div>
<div><input type="submit" value="Enviar"></div>
</form>
<ul class="errores"></ul>
</body>
<script>
$("form").submit(finalValidation)
let errores = [];
function ValidateName(){
let nameValue = $("#name").val()
if(nameValue == ""){
errores = "Ingrese su nombre";
return false
}
return true
}
function finalValidation(e){
if(ValidateName()){
alert("Form enviado!")
} else{
let ul = document.createElement("ul")
for(let i = 0; i < errores.length; i++){
let li = document.querySelector("li")
console.log(li)
}
e.preventDefault()
}
}
</script>
</html>