Reputation:
I have this in JQuery:
$("form").validate({ rules: {
captcha: {
required: true,
remote: {
url: "gb_include/captcha.php",
type: "post"
},
}
},
messages: {
captcha: "Correct captcha is required."
}});
$("form").submit(function(){
if($(this).valid() == true){ /* submit via ajax */ }
But I have to us .live()
because the form is loaded after $(document).ready()
how can i do that ?
Upvotes: 2
Views: 665
Reputation: 5653
You can create a custom event to run after the form is loaded.
$(document).bind('bindForm', function (e) {
$("#form").validate({ rules: {
captcha: {
required: true,
remote: {
url: "gb_include/captcha.php",
type: "post"
},
}
},
messages: {
captcha: "Correct captcha is required."
}});
$("form").submit(function(){
if($(this).valid() == true){ /* submit via ajax */ }
});
});
Add this after the code that loads the form:
$(document).trigger('bindForm');
Upvotes: 2
Reputation: 28618
Why don't you execute the above code in the .load
callback?
See this SOq:
which has a similar requirement.
Upvotes: 1