Detect enter key pressed

JavaScript          Trackback

Do you want to detect if somebody pressed enter on your form (maybe to prevent form submitting when someone press enter key). Here is jquery code that can help you to detect enter key being pressed:

$('input').keyup(function(e) {
	if(e.keyCode == 13) {
		alert('Enter key was pressed.');

If you want to disable Enter key submitting youw form you can use something like this:

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