How to prevent focus jumping to the address bar when tabbing in IE

I had a simple login form, consisting of username and password fields, which when submitted with the incorrect details would select the contents of the username field using the JavaScript select() command and prompt the user to correct their entry, but when pressing tab to jump to the next field, focus would jump to the address bar. Tabbing worked as expected in Firefox, but I wanted to fix the problem in IE.

I Googled in vain intially, findng a few people with the same problem, but no solution. Then I stumbled across someone offering advice on form validation which mentioned to focus on the field before selecting it, and that was all there was to it. Problem solved!

element.focus();
element.select();

2 Responses

  1. Thank you. This particular issue was vexing me for years, but I was never able to find a fix. This did it!

  2. I have the same problem. Can you clarify what you did?

    I’ve tried this, but this did not work in IE. Do you have any recommendations? Thank you!

    Untitled Page

    function setFocus()
    {
    if ((event.which == 9) || (event.keyCode == 9))
    document.getElementById(“TextBox2″).focus();
    document.getElementyById(“TextBox2″).select();
    }

Leave a Reply