Click here to Skip to main content
15,913,133 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Once i enter key is down in a text box the cursor should go to the next text box(the focus should go to next text box).
Posted

Don't.
That isn't behaviour users are "trained" to expect: ENTER is "New Line", or "Submit Form".
TAB is "Next Field".

And if you subvert that, you confuse users. Which means they are less likely to use your site because it doesn't work the way they expect.
 
Share this answer
 
XML
<script type='text/javascript'>
         $(function(){
             var inputs = $('input, select, textarea, a').not(':input[type=button],:input[type=submit], :input[type=reset], :input[type=password]');
             $(inputs).bind('keydown', function (e) {
                 var self = $(this), form = self.parents('form:eq(0)'), focusable, next;
                 if (e.keyCode == 13) {
                     focusable = form.find('input, select, textarea, a').not(':input[type=button], :input[type=reset], :input[type=password]').filter(':visible');
                     next = focusable.eq(focusable.index(this) + 1);
                     next.focus();
                     e.preventDefault();
                     return false;
                 }
             });
         });
     </script>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900