Skip to content

Instantly share code, notes, and snippets.

@DriesS
Created May 24, 2012 12:41
Show Gist options
  • Save DriesS/2781360 to your computer and use it in GitHub Desktop.
Save DriesS/2781360 to your computer and use it in GitHub Desktop.
Live keypress
$(document).ready(function() {
$('input').live('keydown', function(e) {
var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
if(key == 13) {
var inputs = $(this).parents("form").eq(0).find(":input:text,textarea:visible");
var idx = inputs.index(this);
if (idx == inputs.length - 1) {
inputs[0].select()
} else {
inputs[idx + 1].focus(); // handles submit buttons
inputs[idx + 1].select();
}
return false;
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment