Instantly share code, notes, and snippets.

Embed
What would you like to do?
Form Navigation
// Adds the ability to navigate text boxes while pressing either n or p
$('.bigbox2').keypress(function (e) {
switch (e.which) {
case 78:
case 110:
// N was pressed
el = $(this);
prefix = el.attr('name').replace(/-.*$/, "");
pos = $('input[name|="'+prefix+'"]').index(el);
if (pos < $('input[name|="'+prefix+'"]').length) {
$('input[name|="'+prefix+'"]').eq(pos+1).focus().select();
}
return false;
case 80:
case 112:
// P was pressed
el = $(this);
prefix = el.attr('name').replace(/-.*$/, "");
pos = $('input[name|="'+prefix+'"]').index(el);
if (pos > 0) {
$('input[name|="'+prefix+'"]').eq(pos-1).focus().select();
}
return false;
default:
return true;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment