Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$("#MyForm").submit(function () { Does not work in IE8 but FireFox 8?

Tags:

jquery

$(document).ready(function () {
    $("#MyForm").submit(function () {
        alert("Hello");
        return true;
    });
});

Hi, I have a very simple code above, when I submit the form in IE8 nothing happens, but it works fine in FireFox 8.

I am using jQuery 1.5.1. So is it a problem from old version of jQuery?

like image 815
hardywang Avatar asked Nov 05 '22 10:11

hardywang


1 Answers

I've seen this before in IE8 and IE7. Workaround:

$("#MyForm").submit(function () {
    alert("Hello");
    return true;
});

// change input type to whatever submits the form
$("#MyForm input[type='submit']").click(function(e) {
    e.preventDefault();
    $(this).closest("form").submit();
});
like image 190
karim79 Avatar answered Nov 09 '22 12:11

karim79