Answer the question
In order to leave comments, you need to log in
How to prevent form resubmit via enter?
Good afternoon! I have an Ajax form on my form - after a successful submission, a modal window "Thank you" is displayed.
At this point, you can press "enter" and the form will be submitted twice. How to prevent it?
$(function() {
$('#callBack').submit(function(e) {
var $form = $(this);
$.ajax({
type: $form.attr('method'),
url: $form.attr('action'),
data: $form.serialize()
})
.done(function() {
toggleCall();
toggleCallModalThx();
})
.fail(function() {
toggleCall();
console.log('Fail');
});
e.preventDefault();
});
});
Answer the question
In order to leave comments, you need to log in
Create a variable to record the status - sent / not sent. Before submitting the form using a banal if, check the state of this variable and submit the form only if it has not been submitted before.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question