Reputation: 730
I am using this amazing script for validating my form and for the normal functionality it works great, but I would like to validate the form on a onClick (a href) event instead on the submit (input).. is that possible?
Script: https://github.com/jzaefferer/jquery-validation
It must be something like this, right?
<a href="#" onClick="validate()" >
Upvotes: 1
Views: 1029
Reputation: 388446
You can call the valid() method on the form to see whether it is valid.
<a href="#" onClick="$('myformselecto').valid()" >
I would recommend adding the handler using jQuery rather than inlining it
Upvotes: 6
Reputation: 337743
The jQuery validation plugin hooks to the submit
event of the form. Therefore all you need to do is make the click of that a
element submit the form. Try this:
$('#myLink').click(function(e) {
e.preventDefault();
$('#myForm').submit(); // this will then call the validate() func
});
Upvotes: 1