/ Published in: jQuery
When the maxlength is hit, jumps to the next form field. Just put the select on all the relevant form elements, even the last one.
Expand |
Embed | Plain Text
;(function($) { var a = []; $.jumpTo = function(c) { return $(c).each(function(index, e) { a.push($(this)); var ml = $(this).attr("maxlength"), counter = 0; $(this).bind("keyup", function(e) { counter = $(this).val().length; if (ml <= counter) { counter = 0; for (var i = 0; i < a.length; i++) { if ($(this).attr("id") == a[i].attr("id")) { if (a[i+1] && e.keyCode !== 9 && e.keyCode !== 16 && e.keyCode !== 40 && e.keyCode !== 39 && e.keyCode !== 38 && e.keyCode !== 37) { // tab, shift, arrows a[i+1].focus(); } } } } counter++; }); }); }; })(jQuery); // I use the following: $.jumpTo("input.jump-to");
You need to login to post a comment.
