Safe Submit With jQuery

This is just a way to prevent multiple form submissions.



 
Demo
 
What this will do is disable all form inputs when form submit button is clicked to prevent multiple form submission.
Then We will enable all the form inputs after a successful form submission.

The jQuery

$(document).ready(function(){
    $("#submit").click(function(){
    //Disable form inputs
    $(":input").attr("disabled", true);
    var dataString =  'name=test';
    $.ajax({
    type: "POST",
    url: "1.php",
    data: dataString,
    success: function(){
    //Enable form inputs after form successfully submitted
    $(":input").removeAttr('disabled');
    }
    });
    return false;
    });
});

The HTML

<form>
     Name:<input type="test" name="name" id="name" />
     <input type="submit" name="submit" id="submit" />
</form>

Tags: , , , ,

Monday, February 21st, 2011 Tutorials

1 Comment to Safe Submit With jQuery

  • Leslie Moss says:

    Just what I needed.

  • Leave a Reply