Hari Krishna

Hari Krishna

  • 1.5k
  • 129
  • 45.8k

shift focus to next control when Enter key pressed jquery

Nov 23 2017 2:17 AM

$('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;

}

});


Answers (1)