Skip to content

Instantly share code, notes, and snippets.

@tluyben
Created November 29, 2012 11:30
Show Gist options
  • Save tluyben/4168379 to your computer and use it in GitHub Desktop.
Save tluyben/4168379 to your computer and use it in GitHub Desktop.
JQuery enter as tab
$(function(){
$('input').live('keypress', function(eInner) {
if (eInner.keyCode == 13)
{
var el = null; // element to jump to
// if we have a tabindex, just jump to the next tabindex
var tabindex = $(this).attr('tabindex');
if (tabindex) {
tabindex ++;
if ($('[tabindex=' + tabindex + ']')) {
el = $('[tabindex=' + tabindex + ']');
}
}
if (el == null) { // just take the next one
var i = $(":input").index(this)*1;
i++;
el = $(":input:eq(" + i + ")");
if (!el) el = null;
}
if (el == null || el.attr('type') == "submit") {
return true;
}
if (el != null) {
el.focus();
}
return false;
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment