Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Validation not working in IE7 + IE8

I'm trying to use the jQuery Validation plugin on a form on my website. The form works in FF, Chrome, Opera and Safari. It has yet to work in IE7 or IE8.

Below is a simplified version of my code that seems to work in every browser but IE.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">

<title>Form</title>

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.8/jquery.validate.js"></script>

<script type="text/javascript">
    $(document).ready(function(){
       var validator = $("form").validate ({
       rules: {
                first_name: "required"
              },
       messages: {
                first_name: "Enter your firstname"
                 }
       });
    });
</script>

</head>

<body>

<form method="post">
    <label for="first_name" class="hide">First Name</label> 
    <input type="text" name="first_name" value="" id="first_name" class="required" />
    <button type="submit" id="submit" name="submit">Submit</button>
</form>

</body>

</html>

Edit: We now know that using jquery latest, I was using jQuery v1.6, was the issue. I changed back to v1.5.2 and changed

var validator = $("form").validate ({

to:

$("form").validate ({

Everything is working in IE, now. Thanks.

like image 964
magzalez Avatar asked May 09 '11 20:05

magzalez


4 Answers

I think you either need to move back to an earlier version of jquery (1.5.2) or use the newer version of the validation plugin 1.8.0.1.

like image 173
redsquare Avatar answered Nov 07 '22 06:11

redsquare


When you create a new ASP.NET MVC 3 Project in Visual studio, your script folder will by default contain among others:

jquery-1.5.1.min.js 
jquery.validate.min.js (which is version 1.8.0)

One of the first things you might want to do is update the jquery version to the latest version, which today is version 1.7.1

After doing this, your client side validation will stop working in Internet Explorer 7 and Internet Explorer 8.

This is because the jquery.validate version is not compatible with jquery versions > 1.6. The solutions is simple, you need to update your version of jquery.validate as well.

You can find the current version 1.9 from Microsoft’s CDN or the latest version from GitHub here:

Microsoft Ajax CDN: http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js

GitHub Jquery Validation: https://github.com/jzaefferer/jquery-validation/downloads

Remember that you can always find the latest javascript library in Microsofts CDN, see the complete list of available libraries here: http://www.asp.net/ajaxlibrary/cdn.ashx

This information is from my blog post about this problem

like image 16
Stian Avatar answered Nov 07 '22 06:11

Stian


For what it's worth, I had to upgrade to latest JQuery (1.8.2 at this time) and Validate (1.10) to get around this issue.

like image 5
ozz Avatar answered Nov 07 '22 07:11

ozz


I had issues with jquery.validate.js in IE7/IE8. After debugging I noticed the following line was causing the issue (ln 436 in version 1.7):

return $([]).add(this.currentForm.elements)
            .filter(":input")

Replace these two lines with something like:

return $(':input', this.currentForm)

That did the trick for me.

like image 4
nullable Avatar answered Nov 07 '22 08:11

nullable