How do I stop a form from submitting?
How to I stop a form from submitting? I have some validation on my form,
and if the the input isn't correct, then the form should't submit... In my
HTML i have this when clicking submit:
<a href="#"
onclick="setTimeout(function(){document.getElementById('form_4').submit()},
1000);" style="position:static" class="btn-more">Vælg</a>
And the my script looks like this:
$("#form_4 a.btn-more").click(function (e) {
//Validate required fields
for (i = 0; i < required.length; i++) {
var input = $('#' + required[i]);
if ((input.val() == "") || (input.val() == emptyerror)) {
input.addClass("needsfilled");
input.val(emptyerror);
errornotice.fadeIn(750);
e.stopPropagation();
return false;
} else {
input.removeClass("needsfilled");
}
}
//if any inputs on the page have the class 'needsfilled' the form will
not submit
if ($(":input").hasClass("needsfilled")) {
return false;
} else {
errornotice.hide();
return true;
}
});
No comments:
Post a Comment