Phone number autojump

Here is the Javascript code for phone number auto jump.

How to use it?

jump(var1, var2, len)
On onkeyup event call this function.
var: ID of the caller text box element
var2: ID of the text box element to be jumped
len: Length of value in var1 element

Example code

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Phone Number fields auto jump in Javascript</title>
<script type="text/javascript">
function jump(var1, var2, len)
{
if (document.getElementById(var1).value.length >= len)
document.getElementById(var2).focus();
}
</script>
</head>
<body>
<div>
Enter a phone number<br />
(<input id="ph1" name="ph1" type="text" value="" size="3" maxlength="3" onkeyup="jump('ph1','ph2',3)" />)-
<input id="ph2" name="ph2" type="text" value="" size="3" maxlength="3" onkeyup="jump('ph2','ph3',3)" />-
<input id="ph3" name="ph3" tabindex="1006" type="text" value="" size="4" maxlength="4" />
</div>
</body>
</html>

Leave a comment