jquery before form submit
$('#myform').submit(function(event) {
event.preventDefault(); // Prevents the default submit
// your code here (not asynchronous)
$(this).unbind('submit').submit(); // continue the submit unbind preventDefault
})
jquery before form submit
$('#myform').submit(function(event) {
event.preventDefault(); // Prevents the default submit
// your code here (not asynchronous)
$(this).unbind('submit').submit(); // continue the submit unbind preventDefault
})
Sending an Ajax request before form submit
$('form').submit(function(e) {
// this code prevents form from actually being submitted
e.preventDefault();
e.returnValue = false;
// some validation code here: if valid, add podkres1 class
if ($('input.podkres1').length > 0) {
// do nothing
} else {
var $form = $(this);
// this is the important part. you want to submit
// the form but only after the ajax call is completed
$.ajax({
type: 'post',
url: someUrl,
context: $form, // context will be "this" in your handlers
success: function() { // your success handler
},
error: function() { // your error handler
},
complete: function() {
// make sure that you are no longer handling the submit event; clear handler
this.off('submit');
// actually submit the form
this.submit();
}
});
}
});
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us