Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$("#form1").validate is not a function

<script type="text/javascript"> <!-- $(document).ready(function() {        $("#form1").validate({          rules: {           budget: {             required: true,              minlength:3         } ,        duration: {             required: true,             digits:true         },           town: {             required: true,              minlength:2          },         content: {             required: true,             minlength:300           }          },          messages: {            }            });          });         --> </script> 

Two jquery files are included.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript" src="../common/jquery.validate.js"></script> 

are included. There is nothing wrong with the inclusion.

I got an error message

$("#form1").validate is not a function What's wrong?

like image 409
Steven Avatar asked Dec 09 '09 03:12

Steven


People also ask

What does $( this mean in jQuery?

$(this) is a jQuery wrapper around that element that enables usage of jQuery methods. jQuery calls the callback using apply() to bind this . Calling jQuery a second time (which is a mistake) on the result of $(this) returns an new jQuery object based on the same selector as the first one.

What is $( this in JavaScript?

$(this) is a jQuery object and this is a pure DOM Element object. See this example: $(".test"). click(function(){ alert($(this). text()); //and alert(this.

When we use $( this code?

Explanation: The $(this) selector is used to select current HTML elements. 19.

What does $() short and stand for in jQuery?

$ is a short form of jQuery function. $() = jQuery() = window. $() = window. jQuery() $()/jQuery() is a selector function that selects DOM elements.


2 Answers

Put the jQuery script tag before the script tag for validation

I just encountered this extremely frustrating error and lost the better part of an hour to it, for lack of a workable answer online. I confirmed in Firebug that I was hitting the CDN for both jQuery and validation.

In the end, changing this:

    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script>     <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.4.min.js"></script> 

to this:

    <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.4.min.js"></script>     <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script> 

was all I needed.

like image 54
Jay Avatar answered Nov 12 '22 08:11

Jay


I had this same issue. It turned out that I was loading the jQuery JavaScript file more than once on the page. This was due to included pages (or JSPs, in my case). Once I removed the duplicate reference to the jQuery js file, this error went away.

like image 21
Michael Sobczak Avatar answered Nov 12 '22 08:11

Michael Sobczak