Automatically Move Cursor to Next Field When TextBox is Full

  1. <html  
  2.     xmlns="http://www.w3.org/1999/xhtml">  
  3.     <head>  
  4.         <title>JavaScript to automatically move from one field to another field</title>  
  5.         <script type="text/javascript">  
  6. function movetoNext(current, nextFieldID) {  
  7. if (current.value.length >= current.maxLength) {  
  8. document.getElementById(nextFieldID).focus();  
  9. }  
  10. }  
  11. </script>  
  12.     </head>  
  13.     <body>  
  14.         <b>Enter your Text:</b>  
  15.         <input type="text" id="first" size="4" onkeyup="movetoNext(this, 'second')" maxlength="3" />  
  16.         <input type="text" id="second" size="4" onkeyup="movetoNext(this, 'third')" maxlength="3" />  
  17.         <input type="text" id="third" size="5" maxlength="4" />  
  18.     </body>  
  19. </html>