Skip to content

Instantly share code, notes, and snippets.

@stvedt
Created August 31, 2012 20:06
Show Gist options
  • Save stvedt/3558237 to your computer and use it in GitHub Desktop.
Save stvedt/3558237 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
$('input').keyup(function(){
var $this = $(this);
var characters = $this.val().length;
var maxLength = $this.attr('maxLength');
if( characters == maxLength){
$this.next().focus();
}
});
});
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Auto Advance Text-Fields</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script>
</script>
</head>
<body>
<p>
Phone Number:
<input name="phone1" type="text" maxlength="3" size="1">
<input name="phone2" type="text" maxlength="3" size="1">
<input name="phone3" type="text" maxlength="4" size="1">
</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment