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

前端 未结 10 1434
傲寒
傲寒 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:17

    I've adapter the answer of ltiong_sh to work for me:

    function nextField(current){
        var elements = document.getElementById("my-form").elements;
        var exit = false;
        for(i = 0; i < elements.length; i++){   
            if (exit) {
                elements[i].focus();
                if (elements[i].type == 'text'){
                    elements[i].select();
                }   
                break;
            }
            if (elements[i].isEqualNode(current)) { 
                exit = true;
            }       
        }
    }
    

提交回复
热议问题