1

I am trying to validate a form using jquery's validate function. When I trigger the .valid() function, I get a 'Cannot read property call of undefined.

<script>
$("#form1").validate({
    rules: {
        EditSubName: {
            required: true, 
        }, 
        EditSubStreetNumber: {
            required: true, 
        },
        EditSubStreetName: {
            required: true  
        },
        EditSubSuburb: {
            required: true, 
        },
        EditSubState: {
            required: true,
            lettersonly: true,  
        },
        EditSubPostcode: {
            required: true, 
        },
        EditSubEmail: {
            email: true,    
        }
    },

    errorPlacement: function(error,element) {
         return true;
    },
    highlight: function(element) {
        $(element).closest("input")
        .addClass("textbox_001_err")
        .removeClass("textbox_001");
    },
    unhighlight: function(element) {
        $(element).closest("input")
        .removeClass("textbox_001_err")
        .addClass("textbox_001");
    },  
    submitHandler: function(form) {
        alert('Submitting Entered');
        //Update only
            if($("#radiono").prop("checked") == true)
            {
                alert('Entered Radio No');
                  $(".blackout").css("display", "none");
                   $.ajax({
                    url: 'save/saveSubjectonly.asp',
                    type: "POST",
                    data: {
                        SubjectID: $('#DefSubID').val(),
                        name: $('#EditSubName').val(),
                        dob: $('#EditSubDOB').val(),
                        email: $('#EditSubEmail').val() ,
                        telephone: $('#EditSubTelephone').val() ,
                        mobile: $('#EditSubMobile').val() ,
                        fax: $('#EditSubFax').val() ,
                        streetnumber: $('#EditSubStreetNumber').val() ,
                        streetname: $('#EditSubStreetName').val() ,
                        suburb: $('#EditSubSuburb').val() ,
                        postcode: $('#EditSubPostcode').val() ,
                        state: $('#EditSubState').val() ,
                        notes: $('#EditSubjectNotes').val(),
                        activalue: $('input:checkbox:checked').val(),
                        companyname: $('#EditCompanyName').val()
                    },
                    success: function(result){

                            //location.reload()

                    }
                });

            }; 
            //Made changes for all
            if($("#radioyes").prop("checked") == true)
            {
                    $(".blackout").css("display", "none");
                    $.ajax({
                    url: 'save/saveSubjectandupdate.asp',
                    type: "POST",
                    data: {
                        SubjectID: $('#DefSubID').val(),
                        name: $('#EditSubName').val(),
                        dob: $('#EditSubDOB').val(),
                        email: $('#EditSubEmail').val() ,
                        telephone: $('#EditSubTelephone').val() ,
                        mobile: $('#EditSubMobile').val() ,
                        fax: $('#EditSubFax').val() ,
                        streetnumber: $('#EditSubStreetNumber').val() ,
                        streetname: $('#EditSubStreetName').val() ,
                        suburb: $('#EditSubSuburb').val() ,
                        postcode: $('#EditSubPostcode').val() ,
                        state: $('#EditSubState').val() ,
                        notes: $('#EditSubjectNotes').val(),
                        activalue: $('input:checkbox:checked').val(),
                        companyname: $('#EditCompanyName').val()
                    },
                    success: function(result){
                            alert('Success');
                            //location.reload()

                    }
                });
            } 
    },
});
</script> 

I am not sure as to why this is happening. I know that it does not go into the SubmitHandler because none of the alert message trigger.

3 Answers 3

2

I found the problem. What I had forgotten is that the lettersonly in the EditSubState rule is part of the additional-methods.js which was not included in the page.

Once I have included that, the validation works without a problem.

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

1 Comment

I had the same error when trying to use the 'require_from_group' rule without including 'additional/require_from_group.js'.
0

You've got trailing commas in your validation attributes within rules object.

    rules: {
        EditSubName: {
            required: true
        }, 
        EditSubStreetNumber: {
            required: true 
        },
        EditSubStreetName: {
            required: true  
        },
        EditSubSuburb: {
            required: true
        },
        EditSubState: {
            required: true,
            lettersonly: true
        },
        EditSubPostcode: {
            required: true
        },
        EditSubEmail: {
            email: true 
        }
    },

Comments

0

I haven't used this library for jquery, but for the docs, I think you are missing one parameter for each one of your functions or "methods".

For the docs the highlight function must be defined as follows:

$(".selector").validate({
  highlight: function(element, errorClass) {
    $(element).fadeOut(function() {
      $(element).fadeIn();
    });
  }
});

I think JS is trying to call that specific signature, but there are no functions defined for that, so there you have the undefined.

Here are the docs: http://jqueryvalidation.org/validate

Also, the commas that mention Papa are wrong.

Comments

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.