My question is similar to this one: Call javascript function from jquery success; but I'm not using AJAX.
Very simply, I'm validating a form (just the zipcode) as part of a Google Maps web app. The validation code is as such:
$(document).ready(function($)
{
$("#clientInput").validate
({
debug: true,
rules:{zipcode: {required:true, minlength:5, maxlength:10, digits: true}},
messages: {zipcode: {required: "You need to provide at least a zipcode.", minlength: "Please enter at least 5 digits", maxlength: "You've entered too many digits, please re-enter."}},
});
searchlocations();
});
The bold function call is what's stymieing me, it's a call to the Google Map API function but it never gets called. The Google Map javascript is loaded before this code (although it's in a separate file) and before I added the validation code I called the function through the Submit button's onclick() event.
How can I get this function called on successf开发者_开发知识库ul validation of the form?
TIA!
You need to make the function the submitHandler
for the validation.
Chuck is right on; here's an example to help, though:
$(document).ready(function($)
{
$("#clientInput").validate
({
debug: true,
rules:{zipcode: {required:true, minlength:5, maxlength:10, digits: true}},
messages: {zipcode: {required: "You need to provide at least a zipcode.", minlength: "Please enter at least 5 digits", maxlength: "You've entered too many digits, please re-enter."}},
submitHandler: function() {
searchlocations();
}
});
});
If you only need to call searchLocations, you can make it even simpler by just assigning the searchLocations function directly:
submitHandler: searchLocations
精彩评论