Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Auto Tab //JavaScript Function (See related posts)


Auto tabulation of text inputs with maxlength setted

Usage: just add the code on the end of your page or call it on the onload event (worse solution) and "the enter tabulation" will be added for all fields enclosed by the <form> tag.

[UPDATED CODE AND HELP CAN BE FOUND HERE]


@REQUIRES Event-Listener


   1  
   2  //Requires http://www.jsfromhell.com/Geral/event-listener
   3  
   4  //+ Jonas Raoni Soares Silva
   5  //@ http://jsfromhell.com/forms/auto-tab [v1.0]
   6  
   7  autoTab = function(){
   8  	for( var d, f = ( d = document ).forms, i = f.length; i; addEventListener( f[--i], "keyup", function( e ){
   9  		var el, k = String.fromCharCode( e.key ), l = ( e = e.target ).value.length;
  10  		if ( l >= ( e.getAttribute( "maxlength" ) || l + 1 ) && /[\wÀ-ÿ ]/.test( k ) ){
  11  			for( l = k = ( el = e.form.elements ).length; el[--k] != e; );
  12  			while( !(e = el[ k = ++k * ( k < l ) ]).type || e.disabled );
  13  			e.focus();
  14  		}
  15  	} ) );
  16  };

You need to create an account or log in to post comments to this site.


Click here to browse all 5502 code snippets

Related Posts