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

Asked

Viewed 28 times

0

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

1 answer

0

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

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 file . aspx put the function call in the onkeydown event: Ex: < body onkeydown="Entercomotab(Event)">

Browser other questions tagged

You are not signed in. Login or sign up in order to post.