Anthony1312002
Programmer
I have a form that has six fields. Is there a script that will allow a user to use the enter key instead of the tab key to get from one field to the next and then at the end of the form, fire the submit button?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
function changeEnter() {
// makes the enter key work as tab key on forms
if (event.keyCode == 13) {
try {
this.form.elements[window.tabOrder[(this.index + 1)]].focus();
} catch(el) {}
return false;
}
}
function setChangeEnter(f) {
// attaches changeEnter() to form elements, except SUBMIT, BUTTON, TEXTAREA, HIDDEN
if (f) {
window.tabOrder = [];
var els = f.elements;
for (var x = 0, ndx = 0; x < els.length; x++) {
if (!els[x].type || els[x].type.toLowerCase().contains("submit","button","textarea","hidden")) {
continue;
}
else {
window.tabOrder[window.tabOrder.length] = x;
els[x].index = ndx++;
els[x].onkeydown = changeEnter;
}
}
}
}
window.onload = function() {
setChangeEnter(document.getElementById("myFormId"));
}
<body onload="setChangeEnter(document.getElementById('myFormId'));">