Home Ask Login Register

Developers Planet

Your answer is one click away!

Shesha February 2016

Keypress not working in IE (Keydown and Keyup posting the form)

I am working in a form. In which I have used validate plugin to show validation messages. If the user press enter key, I have to validate the form and show if the name is already exists.

$('#name').bind("keypress", function (e) {
    if (e.keyCode == 13) {
        return false;

This code is woking fine in chrome and firefox. I need to clear the validation message which i shown manually without using plugin. But this event not triggering in IE. If I use keydown/keyup the form will be posted without showing validation message. Hence duplicate names will be added in portal.

Can anyone suggest fix for this issue ??


Shubham Dubey February 2016

Use e.preventDefault() outside if condition.

Ilya February 2016

Using jQuery, event.which should work in all cases. You can even test that it's working in your browser from the doc page.

If you want to dive into details, that page has lots of infos, especially for older IE versions, and also includes a nice test script.

Post Status

Asked in February 2016
Viewed 1,805 times
Voted 13
Answered 2 times


Leave an answer

Quote of the day: live life