0

Sample Code that I'm using:

e.keyCode == 13 if (e.which==13) { e.preventDefault(); }

Is any idea apart from this?

Andrew
  • 4,443
  • 5
  • 33
  • 75
JeevaRekha
  • 383
  • 1
  • 7
  • 21
  • possible duplicate of [Enter key press event in JavaScript](http://stackoverflow.com/questions/905222/enter-key-press-event-in-javascript) – jean Jan 28 '15 at 12:43
  • it would only be a duplicate of the mentioned question if this one also applies to forms, which the op didn't specify if it was or not. (Though I assume it is because of the use of preventDefault, but that's just a guess.) – Jon Adams Jan 28 '15 at 15:14

1 Answers1

0

try this

var variablename= (e.keyCode ? e.keyCode : e.which);
     if(code == 13) { //keycode of Enter key
       alert('enter key pressed');
     }

if you are using jquery

$('input[type=text]').on('keyup', function(e) {
    if (e.which == 13) {
        e.preventDefault();
    }
});
Arunprasanth K V
  • 20,733
  • 8
  • 41
  • 71