How to implement in VB .ASPX the action of the ENTER key as TAB?

0

I would like to know how to implement in the boby onKeyDown event of the .aspx file so that when the ENTER key (code = 13) is pressed it behaves like the TAB key (code = 9). This is generic so it can be reused on other screens.

    
asked by anonymous 16.05.2017 / 17:07

1 answer

0

1 Create the function to be used on the screen or in an external script file. In my case I created the name of EnterComoTab, below code below:

function EnterComoTab (e) {             var evt = (document.all)? event: e;             var charCode = (document.all)? evt.keyCode: evt.which;

        if (charCode == 13) {
            event.preventDefault()
            const inputs =
                Array.prototype.slice.call(document.querySelectorAll('input.form-control[type=text]'))
            const index =
                (inputs.indexOf(document.activeElement) + 1) % inputs.length
            const input = inputs[index]
            input.focus()
            input.select()
        }

}

2º In the body of the .aspx file put the function call in the onkeydown event: Ex: < body onkeydown="EnterComoTab (event)" >

    
16.05.2017 / 17:14