0

i am newbie in jquery. i searched in google and i got Validation Plugin. but it's not working. i have attached jquery.validate.js in my header part.

my code looks like...

  <form action="" method="" id="contact">
            <div class="form-group"">
                <label> Your Name </label>
                <input type="text" class="form-control" placeholder="Enter Your Name" id="firstname" required="" minlength="5"/>
            </div>

            <div class="form-group">
                <label> Your E-mail </label>
                <input type="email" class="form-control" placeholder="Enter Your Email" id="email"/>
            </div>
  <button type="submit" class="btn btn-primary btn-lg"> Send</button>
 </form>

  <script type="text/javascript"> 
    $('#contact').validate({
     success: function(label){
    label.addClass("has-success").text("ok");
    }
  });
</script>

but it's not validating my field... Can anyone say how to use it? i know i am doing something wrong here but i am newbie so...

2
  • 2
    Where is the submit button? Commented Oct 23, 2013 at 10:22
  • sorry i forgot to copy that Commented Oct 23, 2013 at 10:25

3 Answers 3

1

Did you include jquery-plugin validation.js file in your project directory?? If no then you need to include http://www.websitecodetutorials.com/code/jquery-plugins/validation.js

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

3 Comments

i have downloaded files from above given link. in that they have given jquery.validate.js that i included.
See the js fiddle link..jsfiddle.net/shaneblake/RQMaV might be this will help you
i just put $('#contact').validate() in downside of form and it worked. Thanks a lot... one more question i am adding bootstrap 3.0 has-success class when it's success but it's not taking that class... pls check my edited code...
1

The submit button is essencial since it fires the validate function:

$("#myform").validate({
  submitHandler: function(form) { // this line is important
    form.submit(); // with this line the validate function gets fired
  }
 });

perhaps you should also try following:

– make sure your jquery library is correctly embedded in your document

– make sure your validation.js is in the correct folder

1 Comment

i just put $('#contact').validate() in downside of form and it worked. Thanks a lot... one more question i am adding bootstrap 3.0 has-success class when it's success but it's not taking that class... pls check my edited code...
1

Try using document ready instruction:

$(function(){
   $('#contact').validate();
});

it works: http://jsfiddle.net/RQMaV/15/

1 Comment

i just put $('#contact').validate() in downside of form and it worked. Thanks a lot... one more question i am adding bootstrap 3.0 has-success class when it's success but it's not taking that class... pls check my edited code...

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.