1

I am using jquery form validation to validate my form but I am getting the following errors:

         Uncaught ReferenceError: jQuery is not defined jquery.validate.js:1178
Uncaught TypeError: undefined is not a function bootstrap.js:29
Uncaught ReferenceError: $ is not defined mimi.html:20

here's my code :

<!DOCTYPE HTML>
<html>
 <head>
    <link type = "text/css" rel="stylesheet" href="css/bootstrap.css" />

       <script type="text/javascript" src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js"></script>
       <script src="js/bootstrap.js"> </script>
       <script> 
                 $(function(){ 
                                 $('form').validate()
                             }); 
        </script> 
 </head>
 <body> 
 <form class = "well span6"> 

 <label> Username </label> 
 <input type="text" id = "myName" class ="span3" placeholder ="Type your username here..." class = "required"/> 

  <label> Password</label> 
 <input type="text" id "myPassword" class ="span3" placeholder ="Type your password here..." class = "required"/> <br/> 

 <button id = "submit" class ="btn btn-primary">Submit </button>
 <button class = "" > Clear <br/></button><br/> 
 </form> 



 </body> 

</html>

I would appreciate your help folks.

1
  • 2
    The error explains everything perfectly. To use a jQuery plugin, first requires jQuery itself. I don't see jQuery included in your code. Commented Dec 31, 2012 at 23:28

1 Answer 1

4

jQuery Validate requires jQuery. You can include just before the jquery.validate.js script.

<script src="http://code.jquery.com/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js" type="text/javascript"></script>
Sign up to request clarification or add additional context in comments.

4 Comments

o, thanks. I tried that and I also added this: <script> $('#submit').click(function(){ $('form').validate() }); </script>
Now, when I click my button, how come I dont get an error message or anything?
@Stranger, your original question has been correctly answered. Please accept it and post a new question about your new issue. BTW- binding .validate() to a click handler is not the correct way to use the plugin.
Sounds like it's in place, then. Calling .validate the first time will initialize the plugin. You can supply additional options to add rules and modify the behavior for adding/clearing errors (such as adding or removing CSS selectors to indicate a field is invalid). Documentation is here: docs.jquery.com/Plugins/Validation

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.