Posted By

frankyfish on 03/17/10


Tagged

form javascript plugin input jquery


Versions (?)

jQuery maxLength input


 / 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: $("#telephone1").maxLength(3, "#telephone2");

  1. (function($){
  2. $.fn.extend({
  3. maxLength: function(length, nextInput) {
  4. return this.each(function(i, el) {
  5. $(el).keyup(function() {
  6. if($(this).val().length >= length) $(this).val( $(this).val().substring(0, length) );
  7. if(nextInput != null) if($(this).val().length >= length) $(nextInput).focus();
  8. })
  9. })
  10. }
  11. });
  12. })(jQuery);

Report this snippet  

You need to login to post a comment.