jQuery validation plugin error: TypeError: validator is undefined

Damir Mitrovic picture Damir Mitrovic · Sep 13, 2012 · Viewed 96.5k times · Source

Here is html code for the form:

<form method="post" id="login" action="/login">
 <div class="login-element">
    <label for="email">E-Mail</label>
    <input type="text" name="email">
</div>
<div class="login-element">
    <label for="password">Passwort</label>
    <input type="password"  name="password">
</div>
<div class="login-element">
    <input type="submit" value="Login">
</div>
</form>

and here is the code that I used for validation:

    $(document).ready(function() { 
    $("#login").validate({
       debug: true,
       rules: {
            email: {
              required: true,
              email: true
            },
            password: {
              required: true
            }
        },
        messages: {
            email: {
                required: "Please enter a email adress",
                email: "Please enter a valid email address"
            },
            password:"Please enter password"
        }
    });
    });

In the console following error is logged:

TypeError: validator is undefined
...or.settings[eventType] && validator.settings[eventType].call(validator, this[0],...

What could be the issue here?

Answer

Damir Mitrovic picture Damir Mitrovic · Sep 14, 2012

This error happened because I had another html element with same id. After removing that id code worked fine.