Skip to content

Instantly share code, notes, and snippets.

@rajraj
Created March 23, 2011 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajraj/884217 to your computer and use it in GitHub Desktop.
Save rajraj/884217 to your computer and use it in GitHub Desktop.
$(function(){
// Collect all text boxes
$textboxes = $(":text");
// call checkForEnter function when a key is pressed
$textboxes.keydown(checkForEnter);
// This function checks if the Enter key is pressed
// If yes then moves the cursor to the next box
function checkForEnter(event) {
if (event.keyCode == 13) {
numCurrentTextbox = $textboxes.index(this);
if (numCurrentTextbox + 1 != null) {
event.preventDefault();
nextTextbox = $textboxes[numCurrentTextbox + 1];
nextTextbox.select();
return false;
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment