I have a JQuery UI submit button on a form when it's clicked to both prevent double-clicking and to also make it visibly clear that it was in fact clicked properly.
So I use jQuery to do this:
$('input:submit').click(function() {
$(this).button('disable');
});
It works, but the problem is when the user hits their back button it remains disabled. What's the proper way to disable a submit button when clicked? I obviously use jQuery, so preference is to use jQuery.
UPDATE: many people suggested I use $(document).ready(function() {$('input:submit').button('enable');});
to overcome this persistent disabling of the button. It turns out that won't work if it comes before my button initialization call in $(function() {}
. But if I put that button('enable') after my button initialization code, even in the $(function() {})
section, then it works as expected.
But now I realize this whole button disabling only works in Firefox! If I disable the button, the form won't submit in IE and Chrome (haven't tested others)!
UPDATE 2: I finally got this to work, though a bit concerned some browsers are not going to be able to submit things with these workarounds... Here's my final code, would love to hear opinions of potential issues:
$(function() {
$('input:submit').button().click(function() {
$(this).button('disable');
$(this).closest('form').submit();
return false;
});
$('input:submit').button('enable');
});