I have a 3x3 table inside the form. By default, the tab key moves the cursor in horizontal directions along these input fields. When a tab index is specified (as in the example below), the tab key moves the cursor columns wise, not string, as needed.
With various sources from SO answers, I came up with jQuery to use the input key as a tab. But, I could not understand how to follow tabindex, as achieved above, that is, by pressing the enter key instead of the cursor moving along a row of lines, I want it to move along the column. The following is what I still have, any help is appreciated.
Demonstration of how it works at the moment. http://jsfiddle.net/unCu5/125/
Source below code: jquery how to catch input key and change event to tab
<table> <tr> <td><input tabindex="1" placeholder="1" /></td> <td><input tabindex="2" placeholder="2" /></td> <td><input tabindex="3" placeholder="3" /></td> </tr><tr> <td><input tabindex="1" placeholder="1" /></td> <td><input tabindex="2" placeholder="2" /></td> <td><input tabindex="3" placeholder="3" /></td> </tr><tr> <td><input tabindex="1" placeholder="1" /></td> <td><input tabindex="2" placeholder="2" /></td> <td><input tabindex="3" placeholder="3" /></td> </tr> </table> $('input').live("keypress", function(e) { /* ENTER PRESSED*/ if (e.keyCode == 13) { /* FOCUS ELEMENT */ var inputs = $(this).parents("form").eq(0).find(":input"); var idx = inputs.index(this); if (idx == inputs.length - 1) { inputs[0].select() } else { inputs[idx + 1].focus(); // handles submit buttons inputs[idx + 1].select(); } return false; } })
@Dekel's solution works for the displayed html script, but I have a different type of HTML to view. How to fix it?
javascript jquery
user5249203 Jul 20 '16 at 19:36 2016-07-20 19:36
source share