Auto-Jump to Next Form Field

Submitted by:David Villa

Date added:13 October, 2012

Category:JavaScript

You need to give each element a sequentially numbered tab index value in order for this script to work properly.

Tags: auto jump

Code Snippet:

<script type="text/javascript">
function jumpField(elmnt,content)
{
if (content.length==elmnt.maxLength)
{
next=elmnt.tabIndex
if (next<document.forms[0].elements.length)
{
document.forms[0].elements[next].focus()
}
}
}
</script>

<form>
<input size="3" tabindex="1" maxlength="3" onkeyup="jumpField(this,this.value)">
<input size="3" tabindex="2" maxlength="3" onkeyup="jumpField(this,this.value)">
<input size="4" tabindex="3" maxlength="4" onkeyup="jumpField(this,this.value)">
</form>
 
 

Comments