js move focus to next field when enter is pressed

HTML
[Edit]
+
0
-
0

js move focus to next field when enter is pressed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<!doctype html> <html> <body> <input id="text-1" type="text" onkeydown="focusNext(event, 'text-2')"/> <input id="text-2" type="text" onkeydown="focusNext(event, 'text-3')"/> <input id="text-3" type="text"/> <script> function focusNext(e, nextElementId) { // if ENTER if (e.keyCode === 13) { // focus next element document.querySelector('#' + nextElementId).focus(); } } </script> </body> </html>
[Edit]
+
0
-
0

js move focus to next field when enter is pressed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<!doctype html> <html> <body> <input id="text-1" type="text" onkeydown="focusNext(event, 'text-2')"/> <input id="text-2" type="text" onkeydown="focusNext(event, 'text-3')"/> <input id="text-3" type="text"/> <script> function focusNext(e, nextElementId) { // if ENTER if (e.keyCode === 13) { // focus next element document.getElementById(nextElementId).focus(); } } </script> </body> </html>