0

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:

http://jsfiddle.net/ndaMD/

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?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.