1 2 3 4 5 6 7 8 9 10 11 12 13 |
<script> $(window).load(function(){ $('.mybox').keypress(function(e){ if(e.keyCode==13) { $(this).nextAll('.mybox').first().focus(); } }); }); </script> |
and another really easy one
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
jQuery.fn.tabEnter = function() { this.keypress(function(e){ // get key pressed (charCode from Mozilla/Firefox and Opera / keyCode in IE) var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0; if(key == 13) { // get tabindex from which element keypressed var ntabindex = parseInt($(this).attr("tabindex")) + 1; $("[tabindex=" + ntabindex + "]").focus(); return false; } }); } $("[tabindex]").tabEnter(); |
Just change the “tabindex” value on each input text box to be incremental.