27
<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?

Sparky
  • 98,165
  • 25
  • 199
  • 285
Steven
  • 24,410
  • 42
  • 108
  • 130

13 Answers13

34

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.

Community
  • 1
  • 1
Jay
  • 56,361
  • 10
  • 99
  • 123
  • Try to solve this issue since last couple of days. Thanks. Works :) – test Jul 24 '15 at 07:42
  • Any jQuery extension or plugin has to be included after jQuery is, otherwise how is your script to extend it? – Madbreaks Mar 22 '17 at 16:46
  • Mine was caused by that I loaded jQuery from local file system but jQuery-validate from CDN. After I changed to load both from local file system, it immediately works. – Canada Wan Mar 17 '20 at 21:30
21

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.

Michael Sobczak
  • 1,045
  • 1
  • 24
  • 45
4

I had the same issue, and yes I had my jquery included first followed by the jquery validate script. I had no idea what was wrong. Turns out I was using a validate url that had moved. I figured this out by doing the following:

  1. Open firefox
  2. Open firebug
  3. Click the NET tab in firebug. This will show you all the resources that get loaded.
  4. Load your page.
  5. Check the loaded resources and see if both your jquery & jquery.validate.js loaded.

In my situation I had a 403 Forbidden error when trying to obtain (http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js which is used in the example on http://rocketsquared.com/wiki/Plugins/Validation ).

Turns out the that link (http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js) had moved to http://view.jquery.com/trunk/plugins/validate/jquery.validate.js (Firebug told me this when I loaded the file locally as opposed to on my web server).

NOTE: I tried using microsoft's CDN link also but it failed when I tried to load the javascript file in the browser with the correct url, there was some odd issue going on with the CDN site.

scifisamurai
  • 111
  • 1
  • 5
2

youll need to use the latest http://ajax.microsoft.com/ajax/jquery.validate/1.5.5/jquery.validate.js in conjunction with one of the Microsoft's CDN for getting your validation file.

Ibrahim
  • 21
  • 2
2

Had the same issue; validated HTML & found I was missing a name="email" attribute from an <input />. Always validate the HTML to be positive your HTML is valid. After I added it, validate() worked perfectly.

Josh
  • 21
  • 1
1

Make sure that jQuery is using the $ variable, and its not another javascript framework.

Check your doctype: Validate your html, sometimes browsers don't see stuff in quirks mode, or when they encouter malformed html.

Also ensure that jquery.validate.js file is correct.

You can download it below:

http://bassistance.de/jquery-plugins/jquery-plugin-validation/

CodeJoust
  • 3,760
  • 21
  • 23
1

my solution to the problem: in footer add <script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.3.26/jquery.form-validator.min.js"></script>

1

In my case i moved the validate part outside of the document ready function and it works fine for me. I hope it would work for u...

 $(document).ready(function () {
   // paste validate function outside of the document ready function...
});

    $('#form1').validate({

        rules: {
            English_Name: { required: true, minlength: 3 },
            Arabic_Name: { required: true, minlength: 3 },
            latitude: { required: true, min: 16, max: 32, number: true },
            longitude: { required: true, min: 32, max: 52, number: true },
            EmployeeID: { required: true },
            PaymentTypeID: { required: true },
            BusinessTypeID: { required: true },
            SalesTypeID: { required: true },
            OutletLength: { required: true },
            OutletWidth: { required: true },
            CONTACT_PERSON: { required: true },
            MOBILE_NO: { required: true, minlength: 9, maxlength: 13, digits: true },
            TRADE_LIC_DATE: { dateValidation: true },
            CreditLimit: { min: 0, max: 2000000 },
            CreditPeriod: { min: 0, max: 365 },
            EMAIL_ADDRESS: { email: true },
            BusinessClassID: { required: true },
            CustomerClassificationID: { required: true },
            LicenseTypeID: { required: true }
        },
        message: {
            English_Name: {
                required: ''

            },
            ToDate: {
                required: ''

            }




        },
        submitHandler: function (form) { // for demo

            $.ajax({
                type: 'POST',
                url: '/sfa/Verification/SaveDataInDatabase',
                data: $('form').serialize(),
                beforeSend: function () {
                    $('.submitBtn').attr("disabled", "disabled");
                    $('.modal-body').css('opacity', '.5');
                },
                success: function (msg) {


                    $("#form1").trigger('reset');
                    $('.modal').modal('hide');
                    $('.submitBtn').removeAttr("disabled");
                    $('.modal-body').css('opacity', '');
                }
            });
        }
    });
Hamza Amin
  • 11
  • 2
1

Check if you use Proxy.

I've got this problem in Mozilla Firefox, I thought it's some issue related to the Firefox itself. Later I found out that I am using a proxy server. When I unchecked the proxy, everything got fine.

Siamak Motlagh
  • 5,028
  • 7
  • 41
  • 65
1

Probably the browser first downloaded the validade script and then jQuery. If the validade script be downloaded before loading jQuery you'll get an error. You can see this using a tool like firebug.

Try this:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script>
    function LoadValidade() {
        var a = false;
        try {
            var teste = $('*');
            if(teste == null)
                throw 1;
        } catch (e) { 
            a = true; 
        }

        if (a){ 
            setTimeout(LoadValidade, 300);
            return;
        }

        var validadeScript = document.createElement("script");
        validadeScript.src = "../common/jquery.validate.js";
        $('head')[0].appendChild(validadeScript);
    } 
    setTimeout(LoadValidade, 300);
</script>
Allan Pereira
  • 2,572
  • 4
  • 21
  • 28
Vismari
  • 745
  • 3
  • 12
0

If you had a link I could look to see what the issue is but here are a couple questions and things to check:

  • Is the ID for your form named "form" in the HTML?
  • Check to see if messages are required, maybe there is some imbalance in parameters
  • You should also add the 'type="text/javascript"' attributes where you are getting jQuery from Google

Also, if you're going to use the Google CDN for getting jQuery you may as well use Microsoft's CDN for getting your validation file. Any of these URLs will work:

Liam
  • 1,712
  • 1
  • 17
  • 30
0

Maybe silly, but check that you inline script is AFTER you include the script tags.

fredrik
  • 17,537
  • 9
  • 51
  • 71
  • If you use Firbug: test to write $.fn.validate in the console and see if it's declared. Are you using any other js-librarys in the same solution? – fredrik Dec 09 '09 at 12:39
0

I had this issue, jquery URL was valid, everything looked good and validation still worked. After a hard refresh CTL+F5 the error went away in Chrome.

bradley32110
  • 53
  • 1
  • 9