2

I have been trying to validate a form with jquery validate plugin.As a newbie i am facing problem with that.Here is the code

$(document).ready(function() {
  $("#log-form").validate({
    errorElement: 'div',
    rules: {
      "username": {
        required: true,
        minlength: 5
      },
      "password": {
        required: true,
        minlength: 5
      }
    },
    messages: {
      username: {
        required: "Provide a username,sire",
        minlength: "Username with length 5 atleast,is required"
      },
      password: {
        required: "Provide a password,sire",
        minlength: "Minimum length of 5 is required for password,sire"
      }
    }
    submitHandler: function(form) {
      form.submit();
    }
  });
});
<form name="log-form" id="log-form" method="post" action="check_login.php">
  <label for="username">Username</label>
  <input type="text" class="" id="username" name="username">
  <br>
  <label for="password">Password</label>
  <input type="password" class="" id="password" name="password">
  <br>
  <button type="submit" name="sub-btn" class="sub-btn">Login</button>>
</form>

The validation is not working as i change field after typing in one neither on submiting the form.

Jatin
  • 3,065
  • 6
  • 28
  • 42
pramod
  • 33
  • 1
  • 3
  • 1
    There is a syntax error in your code, missing `,` after the `messages` property. Please check [How can I debug my JavaScript code?](http://stackoverflow.com/questions/988363/how-can-i-debug-my-javascript-code) – Ram Oct 13 '14 at 01:13
  • you need to add in that javascript – Josua Marcel C Oct 13 '14 at 01:25
  • @JosuaMarcelChrisano actually i was using script tag,but didn't added that here,thanks BTW – pramod Oct 13 '14 at 02:01

1 Answers1

1

As per @unidentified: There is a syntax error in your code, missing , after the messages property. Please check How can I debug my JavaScript code?

$(document).ready(function() {
  $("#log-form").validate({
    errorElement: 'div',
    rules: {
      "username": {
        required: true,
        minlength: 5
      },
      "password": {
        required: true,
        minlength: 5
      }
    },
    messages: {
      username: {
        required: "Provide a username,sire",
        minlength: "Username with length 5 atleast,is required"
      },
      password: {
        required: "Provide a password,sire",
        minlength: "Minimum length of 5 is required for password,sire"
      }
    },                // syntax error, comma was missing here
    submitHandler: function(form) {
      form.submit();
    }
  });
});
Community
  • 1
  • 1
AmanVirdi
  • 1,667
  • 2
  • 22
  • 32