1

Following my code:

<form action="test.php">
<input type="text" onkeyup="if(event.keyCode==13) console.log('something');"/>
<input type="submit"/>
</form>

How to disable submit of form with ENTER key and run correctly the onkeyup with pure javascript?

user2992868
  • 157
  • 1
  • 1
  • 5

1 Answers1

1

return false will prevent from submitting

if( event.keyCode== 13 ) {
  console.log('something');
  return false;
}
Praveen
  • 55,303
  • 33
  • 133
  • 164
  • It's works inline, but not if onkeyup calls a function... http://jsfiddle.net/wrhSy/ – user2992868 Nov 18 '13 at 09:24
  • @user2992868 check this fiddle http://jsfiddle.net/wrhSy/2/ Also take a look at this [question](http://stackoverflow.com/questions/3396754/onkeypress-vs-onkeyup-and-onkeydown) – Praveen Nov 18 '13 at 09:33