Created
July 20, 2010 17:02
-
-
Save jimfleming/483224 to your computer and use it in GitHub Desktop.
Auto-select next field as the user (de-)fills them. Useful for three phone number fields.
This file contains 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 $phone1 = $('input#phone1'); | |
var $phone2 = $('input#phone2'); | |
var $phone3 = $('input#phone3'); | |
$phone1.change(function() { | |
if ($phone1.val().length == 3) // if they've typed 3 characters | |
$phone2.focus(); // select the next field | |
}); | |
$phone2.change(function() { | |
if ($phone2.val().length == 3) // if they've typed 3 characters | |
$phone3.focus(); // select the next field | |
else if ($phone2.val().length == 0) // if they backspace to 0 characters | |
$phone1.focus(); // select the previous field | |
}); | |
$phone3.change(function() { | |
if ($phone3.val().length == 0) // if they backspace to 0 characters | |
$phone2.focus(); // select the previous field | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment