/ Published in: jQuery
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");
Example: $("#telephone_1").maxLength(3, "#telephone_2");
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
(function($){ $.fn.extend({ 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(); }) }) } }); })(jQuery);