I want to prevent multiple submit if someone click on one of the submit buttons multiple times.
How can unbind
or undelgate
in this case th
There are two ways of doing this as pointed out by cHao.
$('form button').prop('disabled', true);
or
$('form button').attr('disabled', 'disabled');
If you are using ASP.NET MVC Data Annotations for Client side Validation, you have to validate the form first -
// To prevent multiple post
function buttonsubmit() {
$('form').submit(function () {
if ($('form').valid()) {
$(this).find("input[type='submit']").prop('disabled', true);
}
});
}
If you have users who insist on having an active submit button all the time you can use a variable to track the progress. Something like this:
saving_record = 0; //set variable to show if form is in submission
$(document).ready(function () {
$('#form').on('submit', function (e) {
if (saving_record === 0) { //If not submitted yet, submit form
saving_record = 1; //Set variable to show form is in submission
$.ajax({
success: function (data) {
saving_record = 0; //Reset variable to allow record update
},
error: function (data) {
saving_record = 0; //Reset variable to allow record update in case of error
}
})
}
});
});
$(document).ready(function(){
$('div.ajax form').submit(function(){
$(this).do_some_stuff();
return false;
});
});
This works on submit
$("form").submit(function() {
// submit more than once return false
$(this).submit(function() {
return false;
});
// submit once return true
return true;
});
when you click the button within the function add the attr(disabled) which will make the button inactive.
$("form Button").attr("disabled","1");
should prevent multiple submissions