Answer the question
In order to leave comments, you need to log in
I'm building a website on a resume, how can I prevent the form from reloading the page (code inside)?
There are several forms on the page, they are validated by the jQuery plugin. And if the validation is successful, I need the form fields to be cleared and a message appears that we will call you back. But as soon as the validation passes, the page is successfully updated.
<form class="form js-form" id="form-request" role="form">
<input class="name" placeholder="Full name" type="text" name="name">
<input class="email" placeholder="Email Address" type="email" name="email">
<input class="phone" placeholder="Phone Number" type="tel" name="tel">
<button type="submit" class="btn">request a quote</button>
</form>
$('.js-form').each(function () {
$(this).validate({
rules: {
email: {
required: true,
email: true
},
name: {
required: true,
minlength: 2
},
tel: {
required: true,
digits: true,
rangelength: [5, 11]
},
submitHandler: function () {
alert('почему он не срабатывает? и как очистить поля)?');
closeModal();
}
}
});
});
Answer the question
In order to leave comments, you need to log in
In general, the mistake was stupid. I wrote the submitHandler property in rules.
corrected code)
$('.js-form').each(function () {
$(this).validate({
rules: {
email: {
required: true,
email: true
},
name: {
required: true,
minlength: 2
},
tel: {
required: true,
digits: true,
rangelength: [5, 11]
}
},
-----> submitHandler: function () {
alert('почему он не срабатывает? и как отчистить поля)?');
closeModal();
}
})
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question