Reputation: 12650
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();
});
Upvotes: 1
Views: 158
Reputation: 126547
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.
Upvotes: 1