-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
Community
  • 1
  • 1
andrsnn
  • 1,591
  • 5
  • 25
  • 43
  • 2
    remove the trailing commas from the JSON passed to validate(at the end of `rules` and `messages.email`) – Dr.Molle Dec 18 '13 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 '13 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 '13 at 00:00
  • 1
    at the end of rules....not after rules – Dr.Molle Dec 19 '13 at 00:02
  • Yes that's what I did I will update the code. Also justification for the down vote please. – andrsnn Dec 19 '13 at 02:55
  • Trailing commas is the issue, and that was the case until IE9. So remove comma at the end of your `desc` block and after the `email` message string. – Ryley Dec 19 '13 at 17:21
  • Are you getting any errors in the IE8 console? – nullability Dec 19 '13 at 17:23
  • Still having the same problems, removing commas still makes code inoperative on IE. Strangely it will work randomly. Added IE error above – andrsnn Dec 19 '13 at 17:32
  • I currently have the site hosted locally using XAMPP, it works when I navigate to localhost or open the html file. It WILL NOT WORK if I navigate to //computername or 127.0.0.1 – andrsnn Dec 19 '13 at 17:41
  • 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 '13 at 17:48

2 Answers2

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   
        }
    });
});
Sparky
  • 98,165
  • 25
  • 199
  • 285
  • 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 '13 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 '13 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 '13 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 '13 at 17:58
  • Got it. Ill keep troubleshooting the server. Excellent site! – andrsnn Dec 19 '13 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

Jason
  • 15,017
  • 23
  • 85
  • 116
Suraj Rawat
  • 3,685
  • 22
  • 33
  • **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 '13 at 17:51