Created
January 21, 2009 05:51
-
-
Save asoltys/49867 to your computer and use it in GitHub Desktop.
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
/* jquery.fieldjump.js */ | |
jQuery.fn.jumpsTo = function(element) { | |
this.bind('keyup', {to: element}, function(event) { | |
var to = $(event.data.to) | |
var from = $(event.target) | |
var keys_typed = from.val().length; | |
var keys_required = from.attr('maxlength'); | |
if (isNumber(event.keyCode) && keys_typed == keys_required) | |
{ | |
to.focus(); | |
if (to[0].type == 'text') { | |
to.val(''); | |
} | |
} | |
}); | |
return this; | |
} | |
function isNumber(n) { | |
return (n >= 48 && n <= 57) || (n >= 96 && n <= 105); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment