Skip to content

Instantly share code, notes, and snippets.

@mikehibm
Last active December 13, 2015 18:39
Show Gist options
  • Save mikehibm/4957085 to your computer and use it in GitHub Desktop.
Save mikehibm/4957085 to your computer and use it in GitHub Desktop.
Prevent submiting form and move focus to next input field when Enter key is pressed.
$(function(){
var elements = "input[type=text]";
$(elements).keypress(function(e) {
var c = e.which ? e.which : e.keyCode;
if (c == 13) {
var index = $(elements).index(this);
$(elements + ":gt(" + index + "):first").focus();
e.preventDefault();
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment