views:

28

answers:

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();
});
+1  A: 

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.

Craig Stuntz