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

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

    function nextField(current){
        for (i = 0; i < current.form.elements.length; i++){
            if (current.form.elements[i].tabIndex - current.tabIndex == 1){
                current.form.elements[i].focus();
                if (current.form.elements[i].type == "text"){
                    current.form.elements[i].select();
                }
            }
        }
    }
    

    This, when supplied with the current field, will jump focus to the field with the next tab index. Usage would be as follows

    
    

提交回复
热议问题