How to advance to the next form input when the current input has a value?

前端 未结 10 1435
傲寒
傲寒 2020-11-30 04:08

I am having a form with lots of entries. I would like to change my focus to the next textbox, once I entered the value in the current textbox. and want to continue this proc

10条回答
  •  不知归路
    2020-11-30 04:25

    This simulates a tab through a form and gives focus to the next input when the enter key is pressed.

    window.onkeypress = function(e) {
        if (e.which == 13) {
            e.preventDefault();
            var inputs = document.getElementsByClassName('input');
            for (var i = 0; i < inputs.length; i++) {
            if (document.activeElement.id == inputs[i].id && i+1 < inputs.length ) {
                inputs[i+1].focus();
                break;   
            }
        }
    

提交回复
热议问题