Created
November 29, 2012 11:30
-
-
Save tluyben/4168379 to your computer and use it in GitHub Desktop.
JQuery enter as tab
This file contains hidden or 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
$(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