Input Text maxLength Property - Jump to the next text field when a field's maxlength has been reached: - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text

Description

Input Text maxLength Property - Jump to the next text field when a field's maxlength has been reached:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<form id="myForm">
<input type="text" size="3" tabindex="1" maxlength="3" onkeyup="myFunction(this,this.value)"> -
<input type="text" size="2" tabindex="2" maxlength="2" onkeyup="myFunction(this,this.value)"> -
<input type="text" size="3" tabindex="3" maxlength="3" onkeyup="myFunction(this,this.value)">
</form>//w  w w . j a va  2  s.  com

<script>
function myFunction(x, y) {
    if (y.length == x.maxLength) {
        var next = x.tabIndex;
        if (next < document.getElementById("myForm").length) {
            document.getElementById("myForm").elements[next].focus();
        }
    }
}
</script>

</body>
</html>

Related Tutorials