curly_brackets
curly_brackets

Reputation: 5598

jQuery validate Each

I'm working on a site with many forms, where I use jQuery Validation script.

As it is now, I need to add a form.validate() on all forms. I would like to make a general validation for all forms.

What I came up with, only works on the first form, and not the other ones. Can I somehow make it work on each form??

    if ($('form').length) {
        $('form').validate({
           submitHandler: function() {
            alert("Validated");
           }
        });
    }

Can you see what I could do? ...Or do you know a better way???

Thank you in advance.

Upvotes: 1

Views: 859

Answers (2)

Edgar Villegas Alvarado
Edgar Villegas Alvarado

Reputation: 18344

Your code is right. Make sure your forms have different id's. validate plugin requires it.

Upvotes: 1

Michael J.V.
Michael J.V.

Reputation: 5609

A longshot, since I have no idea how the plugin works but I expect it wants to work on an object created from a single html form:

if($('form').length)
{
    $('form').each(function(i)
    {
        $(this).validate({
            submitHandler: function()
            {
                alert('Validated');
            }
        });
    }

}

Upvotes: 0

Related Questions