Created
May 24, 2012 12:41
-
-
Save DriesS/2781360 to your computer and use it in GitHub Desktop.
Live keypress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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