Reputation: 1365
I'm having trouble using the jQuery validation (http://jqueryvalidation.org/) plugin with one of my forms. I made a jsFiddle so that nobody has to see my ugly coded 9000 lined form:
source:
<form id="yeah">
First name: <input type="text" class="required" id="firstname" minlength=”4”><br>
Last name: <input type="text" name="lastname">
</form>
<a href="#" id="test123">HELLO</a>
$('#test123').click(function(){
$( "#yeah" ).validate({
});
});
Can anyone tell me what's going wrong?
Upvotes: 0
Views: 70
Reputation: 388316
You need to initialize the validator on dom ready and then on the click event call the valid()
method to see whether the form is valid
jQuery(function ($) {
$("#yeah").validate({});
$('#test123').click(function () {
if ($("#yeah").valid()) {
console.log('do')
}
});
});
Demo: Fiddle
Upvotes: 1