Created
September 2, 2016 03:04
-
-
Save mroien/9bce7e442b0f525552850973890b97aa to your computer and use it in GitHub Desktop.
Auto change focus after maxlength
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
var container = document.getElementsByTagName("form")[0]; | |
container.onkeyup = function(e) { | |
var target = e.srcElement; | |
var maxLength = parseInt(target.attributes["maxlength"].value, 10); | |
var myLength = target.value.length; | |
if (myLength >= maxLength) { | |
var next = target; | |
while (next = next.nextElementSibling) { | |
if (next == null) | |
break; | |
if (next.tagName.toLowerCase() == "input") { | |
next.focus(); | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment