I have a large form that I want to navigate through by pressing enter instead of tab. I have a simple script which worked fine until I added some disabled fields into the mix. How can I skip the fields that have the attribute of disabled?
I've tried using a loop but I cannot get it to skip the two disabled fields together and focus to the next one, as it seems to stay on the field before the disabled ones.
Failing that, is there a way to replace the enter keyCode of 13 with the one for tab? I've tried a few solutions here but none of them seem to work
$('input').on('keydown', function (e) {
if (e.keyCode == 13) {
e.preventDefault();
$('input')[$('input').index(this)+1].focus();
}
});
You can use the :enabled selector.
$('input').on('keydown', function (e) {
if (e.keyCode == 13) {
e.preventDefault();
$('input:enabled')[$('input:enabled').index(this)+1].focus();
}
});
JSFiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With