I have a simple script that auto-advances the cursor to the next field in my html form after one character is entered…and it works great for that. This is the simple code:
function autotab(current,to)
{
if (current.getAttribute && current.value.length==current.getAttribute("maxlength"))
{
to.focus()
}
}
Then of course I use the onkeyup to advance it, like this:
<input onkeyup="autotab(this, document.jumble.w1b)" type="text">
Again, that works great. However, when I do Shift+Tab to go one box back, it auto-advances before I can type anything.
Does anyone have a code example of how to make Shift+Tab work? I have tried different variations of trying to use the keycodes to detect shift and tab, but it doesn’t seem to work.
Any help would be greatly appreciated!
You should prevent to.focus in case of
shift + tabjsfiddleEDIT: Add event as first parameter in autotab:
<input onkeyup="autotab(event, this, document.jumble.w1b)" type="text">