0

Disable Enter Keypress on Form Submit & Change it into a tab instead

How do I disable the key "enter keydown" on form submit button, because in a form, when I press "enter", it will submit my form.

I want my enter to become "tab" instead, so when I press enter e.g at

input text id="text_1", i want maybe change it focus to "small_1" (another textfield) , then if I press enter again at small_1, I want change it focus to big_1

and so on

How do I achieve this, I tried jquery autotab but it doesn't work like what I wanted.

Baoky chen
  • 99
  • 2
  • 10

1 Answers1

0

Add a method to watch for the enter key being pressed (using jQuery):

$("#text_1").bind("keyup keypress", function(event){
    var code = event.keyCode || event.which; 
      if (code == 13)  {
          event.preventDefault();
          $('html, body').animate({
              scrollTop: $("#small_1").offset().top
          }, 2000);
          return false;
      }
});

$("#small_1").bind("keyup keypress", function(event){
      var code = event.keyCode || event.which; 
      if (code == 13)  {
          event.preventDefault();
          $('html, body').animate({
              scrollTop: $("#big_1").offset().top
          }, 2000);
          return false;
      }
});

You could set these up with JavaScript to detect the elements (and generate strings for the ids in a for loop) so you don't have to do these for each one, and it would also make it easier to add new ones.

Anurag Srivastava
  • 14,077
  • 4
  • 33
  • 43
Blubberguy22
  • 1,344
  • 1
  • 17
  • 29