-1

I am attempting to implement Jquery validation using this plugin.

I have seen these three links pertaining to this problem: Link 1, Link 2, Link 3

Validation works perfectly on all other browswers, ie Firefox, Chrome, Safari and mobile devices.

I have tried using different JQuery versions, 1.9.0, 1.1.0.2 and 1.5.2. I am using the latest validation 1.11.1.

I ensured my code is wrapped in DOM ready.

Not sure what I may be overlooking, any help/assistance appreciated. Please tell me if you would like me to include html.

My code:

$.validator.setDefaults({
    submitHandler: function() { alert("Report submitted! Thank you!"); }
});

$(document).ready(function() {
    //validate on keyup
    $("#testForm").validate({
        rules: {
            fullname: {
                required: true,
                minlength: 2
            },
            phone: {
                required: true,
                rangelength: [10, 10]
            },
            building: {
                required: true,
                minlength: 2
            },
            room: {
                required: true,
                minlength: 2
            },
            around: {
                required: true,
                minlength: 10
            },
            email: {
                required: true,
                email: true

            },
            desc: {
                required: true,
                minlength: 15
            },
        } // <------- LINE 228
        messages: {
            fullname: {
                required: "Please enter your full name.",
                minlength: "Your fullname must consist of at least 2 characters."
            },
            phone: {
                required: "Please enter a valid 10 digit phone number.",
                rangelength: "Please enter a valid 10 digit phone number."
            },
            email: "Please enter a valid email address."        
        }
    });
});

IE Error given:

Expected identifier, string or number
Line: 228, Char:3

I currently have the site hosted locally with XAMPP. I have found the site will give no errors in IE if:

I navigate to localhost or opening html file directly.

Will not work:

navigate to //computername or 127.0.0.1
10
  • 2
    remove the trailing commas from the JSON passed to validate(at the end of rules and messages.email)
    – Dr.Molle
    Dec 18, 2013 at 23:54
  • I didn't think trailing commas were a problem for IE 8 and up? Just 7 and lower had the problem. Ill try that though thanks!
    – andrsnn
    Dec 18, 2013 at 23:58
  • removing the comma at the end of rules causes the validation to stop working in Firefox. Still nothing in IE
    – andrsnn
    Dec 19, 2013 at 0:00
  • 1
    at the end of rules....not after rules
    – Dr.Molle
    Dec 19, 2013 at 0:02
  • 1
    Trailing commas may or may not be a problem depending on the version of IE (they are sloppy and should be removed), but you are missing a needed comma right after rules on line 228!
    – Sparky
    Dec 19, 2013 at 17:48

2 Answers 2

1

Your code...

    ....
        desc: {
            required: true,
            minlength: 15
        },
    } // <------- LINE 228
    messages: {
    ....

You're missing the comma on line 228...

$(document).ready(function() {
    $("#testForm").validate({
        rules: {
            // rules,
            desc: {
                required: true,
                minlength: 15
            }                       // <-- the "trailing comma" was here
        }, // <------- LINE 228     // <-- you MUST have a comma here
        messages: {
            // messages   
        }
    });
});
5
  • Thank you for this. Very helpful. Still not working when I navigate to //computername or 127.0.0.1. But will work when opening the html or navigating to localhost. Could you shed any light here?
    – andrsnn
    Dec 19, 2013 at 17:55
  • So there should not be trailing commas after each section then? ie room:{}, email: {}, I am very new to JQuery!
    – andrsnn
    Dec 19, 2013 at 17:56
  • @user2210274, no idea what's going on with your server... it should work in all cases since the code runs in the browser and not on the server. Perhaps you're getting older cached versions of your broken code from the server.
    – Sparky
    Dec 19, 2013 at 17:57
  • @user2210274, The root issue is JavaScript. "trailing commas" are commas that come after the LAST item in a list. Think of them as not needed since no item comes after them. Again, study the code in my answer which is correct.
    – Sparky
    Dec 19, 2013 at 17:58
  • Got it. Ill keep troubleshooting the server. Excellent site!
    – andrsnn
    Dec 19, 2013 at 18:05
0

The same problem happened to me

jQuery has removed support of IE8 and older from jQuery 2.0. Try to use on older version of jQuery - something 1.9x as an example.

Make sure to check the documentation of the plugin before using it. The plugin may not be supported with the version of jQuery you are using

1
  • Where does the OP say he's using jQuery 2.0? In fact, he says he's tried, "1.9.0, 1.1.0.2 and 1.5.2", where I assume he meant 1.10.2, along with the latest version of the plugin (1.11.1).
    – Sparky
    Dec 19, 2013 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.