Skip to content

Instantly share code, notes, and snippets.

@asoltys
Created January 21, 2009 05:51
Show Gist options
  • Save asoltys/49867 to your computer and use it in GitHub Desktop.
Save asoltys/49867 to your computer and use it in GitHub Desktop.
/* 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