skwidgets
skwidgets

Reputation: 291

jQuery .delegate Not Working on Form Load via AJAX

I am submitting and loading a new form via AJAX and want to use the same script that the first form uses to submit and load the new form to submit a comment. I have this script commented out so you cannot see it but when I use it, the commentForm.php loads and does not use the jQuery submission. I have tried it many ways with no luck.

$('#quoteForm').delegate('input:submit', 'submit',function(e) {

Any help would be appreciated.

Upvotes: 2

Views: 2183

Answers (1)

karim79
karim79

Reputation: 342775

If your form is getting replaced then you'll need to delegate the event handler to a parent element. And you'll need to bind to the form and not the submit button:

$('body').delegate('form', 'submit', function(e) {

    // and you'll need this to prevent
    // the form's 'default' action
    e.preventDefault(); 

Upvotes: 3

Related Questions