Disable submit button on form submit
Lets consider this classic problem on the web.
Most people are not aware about the difference between double click and single click on the internet. This creates a lot of programming issues for the back-end guy.
<form method=POST>
<input type="text" id="text-input">
<input type="submit" id="submit-button">
</form>
Here is a small jquery snippet which disables the submit button on form submission. The id of the submit button would be submit-button.
$('#submit-button').click(
function(){
$('#submit-button').attr('disabled', true);
$('#submit-button').closest("form").submit();
});
This code solves most of the common problems.
Lets consider the case where there is a jquery form validation also in place.
Here you will need to disable the button only on completely validated form. The code for that goes below
$('#submit-button').click(
function(){
if($('#submit-button').closest("form").validate().form()){
$('#submit-button').closest("form").submit();
$('#submit-button').attr('disabled', true);
}});
Let me know if you find more interesting techniques.



No trackbacks yet.