Bạn đang xem: How to disabled submit button after clicked using jquery
In my django tiện ích I have a form:
SendI wan"t to disable the button once the user has submitted the form. Using other questions, I tried several things, like:
SendWhen I click, the button is disabled... But the form is not submitted. Và for each try I had the same issue: either the button is disabled or the form is submitted. I can"t find how to vì chưng both...
I"m using Chrome. Any idea on why I have this problem? Thank you for your help.
Xem thêm: Mẹ Ít Sữa Phải Làm Sao: Cách Giúp Sữa Về Nhiều, 7 Cách 'Gọi' Sữa Mẹ Về Nhiều Để Cho Con Bú
$("form").submit(function() $(this).find("button
I like this, don"t have lớn 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););
$("form").on("submit", function () $(this).find(":submit").prop("disabled", true););Be sure to lớn run this code only after the HTMLFormElement has been loaded, or else nothing will be bound lớn it. Khổng lồ ensure that the binding takes place, fire this off from within a document-ready block:
// When the document is ready, gọi setup$(document).ready(setup);function thiết đặt () $("form").on("submit", function () $(this).find(":submit").prop("disabled", true); );
$("#form_id").submit(function() $("input
Source: JavaScript Coder
$("form").submit(function disableSubmit() $("input
How about this?
onclick="this.style.visibility="hidden";"I would say, instead of disabled, hide it.
If you want to lớn go with disabled
onclick="this.style.disabled="true";"
I"m using Chrome. Any idea on why I have this problem?
Well, first time I dealt with this, I solved it lượt thích this:
function blockButtons() $("button:submit").click(function() $("button:submit").attr("disabled", true); );This worked perfectly, but... In Mozilla Firefox. The Google Chrome did not submit it, so I changed it khổng lồ this:
function blockButtons() $("button:submit").click(function() var form = $(this).parents("form:first"); $("button:submit").attr("disabled", true); $("button:submit").css("opacity", 0.5); form.submit(); );This worked both in Mozilla Firefox, however, after that some of our users using old versions of IE experienced trouble of having two submits. That is, the one initiated by the javascript, and the one by browser ignoring the fact of onclick & just submitting anyway. This can be fixed by e.preventDefault, I guess.