shift focus to next control when enter key pressed

Posted by Plhkrishna under ASP.NET MVC on 11/23/2017 | Points: 10 | Views : 239 | Status : [Member] | Replies : 2
$('body').on('keydown', 'input, select, textarea,checkbox', function(e) {
var self = $(this),
form = self.parents('form:eq(0)'),
submit = (self.attr('type') == 'submit' || self.attr('type') == 'button'),
focusable,
next;

if (e.keyCode == 13 && !submit) {
focusable = form.find('input,a,select,button,textarea,checkbox').filter(':visible:not([readonly]):not([disabled])');
next = focusable.eq(focusable.index(this)+1);

if (next.length) {
next.focus();
} else {
form.submit();
}

return false;
}
});

.net developer


Responses

Posted by: Pandyamanav on: 11/23/2017 [Member] Starter | Points: 25

Up
0
Down
Hello

First of all i want to say , just focus() is enough to highlight element

Its not like that you should put conditionally

Thanks

Plhkrishna, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pandyamanav on: 11/23/2017 [Member] Starter | Points: 25

Up
0
Down
And you can try

That you can define "Tab Index " to every control

So that you can maintain every element

Thanks

Plhkrishna, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response