In my HTML css:
.edit_field {
height: 50px;
width: 495px;
line-height: 3.6;
}
html:
Try this:
$('#message').keyup(function(e){
if(e.keyCode == 13){
//your code probably want e.preventDefault() as well
}
});
I've found keypress implementation to not be so cross-browser friendly. Just a thought.
Edit: I now remember why this doesn't work in IE8. The enter key (keycode 13) is considered a "Special Key" (as well as others like arrow keys on the keyboard) IE does NOT fire a keypress event for "Special Keys" which is why I had to use keyup.
You can find more info here: http://www.quirksmode.org/dom/events/keys.html
Look under "Special Keys"
e.which doesn't work in IE try e.keyCode, also you probably want to use keydown() instead of keypress() if you are targeting IE.
See http://unixpapa.com/js/key.html for more information.
jQuery keypress() event not firing?
I've encountered this too, particularly with tables using an onKeyDown() in IE7. Other keys fire fine but enter is tricky. I solved mine by moving my onkeydown() trigger about in the HTML, from certain locations it wouldnt pick up enter but would gather others.
If I recall I had it originally in the body tag and moving it to a <div>
just inside the body immediately allowed me to detect enter. I was using jsp with a switch but I dont think its a great deal different