Have an account? Sign in
Login  Register  Facebook
how to make the enter key do the tab key function
When I move in form field I want with 'enter' key move into next field not with 'tab' key this mean I need to build html code which every time user press enter key on a input text tag, following input box must be focused.
Started: September 18, 2011 Latest Activity: September 18, 2011 ajax html keyword
2 Answers
Using jQuery:
$(document).ready(function () {
    $(":input).keypress(function(event) {
        if (event.keyCode === 13 || event.keyCode === 10) // 10 is for mac
            event.preventDefault();
            $(this).next(":input").focus();
        }
    })
});
This may work if all of your input types are at the same level (siblings). Otherwise you may need to cache off the $(":input) array and loop through that manually.

Posted: Go
In: September 18, 2011

Please don\'t do that. It will make users hate your form, The worst thing you can do for a user friendly form is breaking the way forms usually work. Altough, if you really want to do it, you have to use a hander on each input for the enter key (key id is 13) and then focuses the next input using the focus() function. That post might help you
and You are breaking a well established UI/UX principle. It just like making your right mouse button behave like the left one. and the left like the right.

Posted: MacOS
In: September 18, 2011

Hi,why user will hate my form,it that function make move into next filed with enter
September 18, 2011

because you will breaking the way forms usually work
September 18, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer