-2

I have used and seen many desktop softwares . In desktop softwares like tally or anyother desktop software In their data entry form , when we enter and press enter key the focus goes to next input text box and further it goes to submit button and submits to data but in html on pressing enter it directly submits the form I want know how to change this behaviour for html form and make it like desktop so people do not have to make use of mouse as many of my clients are asking for this functionality . I would also like to know are there any javascript libraries that will handle this keyboard routing of key events . I know this can be done with jquery or javacript but I want to know some easy way to do this so that will help to develop apps faster

  • Possible duplicate of [focus on next tabindex of HTML element onEnter keypress by JQuery](http://stackoverflow.com/questions/10742349/focus-on-next-tabindex-of-html-element-onenter-keypress-by-jquery) – Moumit Jun 06 '16 at 05:51

1 Answers1

0

You can easily identify whether enter key is pressed or not by using this script

$(document).keypress(function(e) {
    if(e.which == 13) {
        alert('You pressed enter!');
    }
});

Then make some reference to your submit button. for example:

<input type="submit" id="button">

then use this script

 $(document).keypress(function(e) {
        if(e.which == 13) {
            $("#button").focus();
        }
    });

Hope this will help you.

Deepak
  • 1,373
  • 2
  • 10
  • 31
  • You missed one more point I am saying , suppose there are 5 input text boxes , focus is in the first box and now when the enter key is pressed I need to go focus on other text input box which can be second input box or third or fourth , We can do this same for tab key using tabindex but I need to know it for enter key – Shridhar U Patil Jun 07 '16 at 05:31