Return to Snippet

Revision: 24999
at March 17, 2010 14:13 by frankyfish

Initial Code
		maxLength: function(length, nextInput) {
			return this.each(function(i, el) {  
				$(el).keyup(function() {
					if($(this).val().length >= length) $(this).val( $(this).val().substring(0, length) );
					if(nextInput != null) if($(this).val().length >= length) $(nextInput).focus();

Initial URL

Initial Description
jQuery plugin that let you specify a maximum length on a text field and optionaly specify the change the focus when that maximum length has been reach. Nice when making multiple input text to create a telephone form.
Example: $("#telephone_1").maxLength(3, "#telephone_2");

Initial Title
jQuery maxLength input

Initial Tags
form, javascript, plugin, jquery

Initial Language