How can I focus the next input once the previous input has reached its maxlength value?
a: <input type="text" maxlength="5" />
b: <input type="text" maxlength="5" />
c: <input type="text" maxlength="5" />
If a user pastes text that is greater than the maxlength, ideally it should spill into the next input.
jsFiddle: http://jsfiddle.net/4m5fg/1/
I must stress that I do not want to use a plugin, as I'd much rather learn the logic behind this, than use something that already exists. Thanks for understanding.
If you're focused on creating card(debit/credit) number input type. Then clean an easily manageable jQuery version as follows:
You can use plain JavaScript:
See DEMO.
Check the character length with
el.value.length
. If it is equal to the maximum value, move to the next field by usingfocus()
. Bind this function to the keyup event withonkeyup
so that the function fires every time after the user keys in a character.