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.

3
  • 1
    There is a syntax error in your code, missing , after the messages property. Please check How can I debug my JavaScript code? Commented Oct 13, 2014 at 1:13
  • you need to add <script type="text/javascript"></script> in that javascript Commented Oct 13, 2014 at 1:25
  • @JosuaMarcelChrisano actually i was using script tag,but didn't added that here,thanks BTW Commented Oct 13, 2014 at 2:01

1 Answer 1

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();
    }
  });
});
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.