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

Viewed 113728
<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?

13 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.

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>

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', '');
                }
            });
        }
    });
Related