jQuery: Change an ENTER to a TAB

A common practice in web applications is that the behavior of the ENTER key is not what it usually has by default, and with jQuery you can change that behavior quite easily.

The required code is this:

function enter2tab (e) {
if (e.keyCode == 13) {
cb = parseInt ($ (this) .attr ('tabindex'));

if ($ (': input [tabindex = \ »+ (cb + 1) +' \ ']')! = null) {
$ (': input [tabindex = \ »+ (cb + 1) +' \ ']'). focus ();
$ (': input [tabindex = \ »+ (cb + 1) +' \ ']'). select ();
e.preventDefault ();

return false;}}}

You have to include the enter2tab function in the action where you want it to be applied, without any more mysteries.

Source | Crystalb


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   FERNANDO said

    I tell you, use your code and it does not work for me, I want to control that when pressing ENTER it does the function of a TAB to move the focus to the next input

  2.   Fuck you, I gave birth to you said

    Check the syntax of the code, as it does not work. It will be because of the fucking single quotes that are transformed into a decoration and there are double quotes that do not close.