Disable button after submit with jQuery Disable button after submit with jQuery django django

Disable button after submit with jQuery


Try this:

$('form').submit(function() {  $(this).find("button[type='submit']").prop('disabled',true);});


I like this, don't have to traverse the DOM.Put function on a setTimeout function, this allows make submit and after disable button, even if setTimeout is 0

$(document).ready(function () {$("#btnSubmit").click(function () {    setTimeout(function () { disableButton(); }, 0);});function disableButton() {    $("#btnSubmit").prop('disabled', true);}});


You could disable it upon the parent form's submit event:

$("form").on("submit", function () {    $(this).find(":submit").prop("disabled", true);});

Be sure to run this code only after the HTMLFormElement has been loaded, or else nothing will be bound to it. To ensure that the binding takes place, fire this off from within a document-ready block:

// When the document is ready, call setup$(document).ready(setup);function setup () {    $("form").on("submit", function () {        $(this).find(":submit").prop("disabled", true);    });}