Не срабатывает event.preventDefault()
window.onload = function() {
var input = document.querySelectorAll('form input[name="text"]');
var submit = document.querySelector('form input[type="submit"]');
var form = new Form(input);
submit.addEventListener('click', form.check);
}
function Form(input) {
this.input = input;
this.check = function() {
for (var i = 0; i > input.length; i++) {
if (this.input[i].value == '') {
event.preventDefault();
this.input[i].classList.add('error');
} else {
this.input[i].classList.remove('error');
}
}
};
}
<form action="">
<input name="text" type="name" placeholder="Введите имя"><br>
<input name="text" type="text" placeholder="Введите почту"><br>
<input name="text" type="text" placeholder="Введите телефон"><br>
<input name="submit" type="submit">
</form>