1

I'm using the jQuery validation plugin on a form loaded via ajax.

For whatever reason, it isn't working. Is there something special I need to do b/c it's loaded after js is initialized? Any ideas?

Edit:

Using the code from the plugin site:

$().ready(function() {
    // validate the comment form when it is submitted
    $("form").validate();
});
2
  • When are you calling validate()? It's hard to fix your code without seeing it. Commented Feb 10, 2010 at 21:59
  • You're right, Craig. I've tried several things--including copy/paste the demos from the plugin site. I can get it to work w/o the ajax, but it's a problem with ajax loading... Commented Feb 10, 2010 at 22:01

1 Answer 1

1

When you load a form via AJAX, you can't use a ready event, because that only runs when the page initially loads. Instead, use the loaded callback, e.g.:

$("#formDiv").load("/Path/To/Form", function() { 
    $("#formDiv form").validate();
});

This ensures validate() is called after the AJAX call returns.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.