0

I'm using jQuery Validation Plugin - v1.11.1 and jquery 1.10.2 but below code doesn't work in IE 8. It works fine in IE9 and above and also in other browsers like Chrome.

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <script src="Scripts/jquery_validate.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#btn').click(function() {                 
                $("#form1").validate({                       
                    rules: { 
                        <%= txt.UniqueID %>: "required"
                    },
                    messages: { 
                        <%= txt.UniqueID %>: "Please enter QTY"
                    }                                    
                });
            });
        });     
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    ID
    <asp:TextBox runat="server" ID="txt" ClientIDMode="Static" />
    <asp:Button Text="Test" runat="server" ID="btn" ClientIDMode="Static" />    
</asp:Content>

EDITED:

The reason I wrapped the validate() within $('#brn').Click(function(){}) event is that I have another postBack from GridView RowCommand Event.Is there another way to call jquery validate() only when the button is clicked?

Seehyung Lee
  • 590
  • 1
  • 15
  • 32
  • have you tried enclosing '<%= txt.UniqueID %>' in quotation marks? – Artur Udod Jul 29 '13 at 10:42
  • I see a similar issue here, but it looks like you have a newer version anyway? http://stackoverflow.com/questions/5942327/jquery-validation-not-working-in-ie7-ie8. – Christian Phillips Jul 29 '13 at 10:55
  • You misunderstand what `.validate()` is doing. It's only the initialization routine. If you just want to "test" the form on each click, then use the `.valid()` method. You'll still need to initialize the plugin first on page load. – Sparky Jul 31 '13 at 14:13

2 Answers2

3

Your code incorrectly wraps .validate() inside a click handler...

$('#btn').click(function() {                 
    $("#form1").validate({                       
        ...                             
    });
});

This is wrong because .validate() is only the initialization method of the plugin, so there is no reason to wrap it inside a click handler. The click of the submit button is already automatically captured and handled by the plugin.

This is the proper way to use the .validate() method...

$(document).ready(function() {

    $("#form1").validate({  // initialize the plugin                 
        // rules & options                          
    });

});

Working DEMO using jQuery 1.10.2 and jQuery Validate 1.11.1, tested with IE 81: http://jsfiddle.net/jsDzU/show

1 Tested with a real version of IE 8 installed in Windows XP SP3. Never assume that "IE 8 Mode" in another IE version is an accurate representation of the real thing or an "emulator" - it is not. Microsoft provides free VPC hard drive images for accurate testing in each IE version.

Sparky
  • 98,165
  • 25
  • 199
  • 285
  • I'm using jquery 1.10.2 and jQuery Validation Plugin - v1.11.1 and having the same trouble. Your example won't work on ie8. The alert fires even if the input is empty. – tylik Jul 30 '13 at 13:03
  • It's even worse on ie7. There is a javascript error, and the script just freezes. I thought it was crossbrowser compatible. Is there a way to fix that? – tylik Jul 30 '13 at 13:10
  • 2
    @tylik, I'm not sure what you are doing, but my link was tested in a real version of IE 8 running in Windows XP... and it's working perfectly fine. If you're testing in "IE8 mode" in another version of IE, then your testing methodology is faulty. The various "IE modes" do not accurately represent the behavior of these older versions. – Sparky Jul 30 '13 at 15:41
  • Sorry, you are right. This is really annoying that the emulators don't behave as they should. Well, it's IE... – tylik Jul 30 '13 at 15:49
  • @tylik, the modes are not really "emulators"; they are mostly just for CSS/layout simulation. For more accurate testing, they provide free VPC hard drive images containing each browser version. – Sparky Jul 30 '13 at 16:03
  • I've tried to run ie6 on virtial machine before but it was really slow. I use ietester to test all those old versions. On Ietester the validation plugin worked fine. Although ietester is also not perfect... – tylik Jul 30 '13 at 16:19
  • 1
    @tylik, that's my point. None of these simulations are good enough. The only way to _really_ test a browser version is within that browser version. Since most people do not wish to run multiple installations of Windows, VPC is a perfect solution, albeit performance directly dependent upon your hardware. VPC is running the real browser version, not a simulation. Since "comments" is not the proper section for discussion, this is my last reply on the matter. – Sparky Jul 30 '13 at 16:39
  • Thank you for your answer but my situation prevents me from using your solution. – Seehyung Lee Jul 31 '13 at 04:24
  • @SeehyungLee, why is that? My solution is a basic demo of how the plugin is supposed to be implemented. If you can't implement as designed, you can't expect it to function as designed. – Sparky Jul 31 '13 at 14:01
  • Just to be clear, this fiddle http://jsfiddle.net/jsDzU/show/ does NOT work in emulation mode... – drogon Jan 16 '14 at 03:01
  • @drogon, "emulation mode"? Just to be clear, I never claimed it would nor should you expect it to. "Compatibility Mode" is not an emulator and there's no such thing as an emulator that works "as well" as the real Internet Explorer 8. Read the last paragraph of my answer again. – Sparky Jan 16 '14 at 03:08
0

Yes it works with "jquery-1.4.4.min.js"

you can test here

demo

sandipshirsale
  • 791
  • 7
  • 11