Reputation: 19463
I have a login page which contains 2 input fields & a submit button. I have set the page to auto focus the username input field when the page load with $("#username").select()
.
However, when I press down "tab" key on keyboard, instead of jump to the password field, it jump to the browser address field. I tried to solve it by putting username field with tabindex = 1 and password fiel with tabindex = 2. But the situation still the same.
I notice that if I manually mouse click on the username field or refresh the page, it will jump to password field when "tab" key is pressed.
So, how can I solve it?
Thank you.
Upvotes: 0
Views: 3661
Reputation: 1833
I think you need to use .focus() instead of .select()
$("#username").focus();
Upvotes: 1
Reputation: 3890
Try to use $("#username").focus()
before. I'm not sure selecting an element changes the tabindex. I'm pretty sure focus does.
BTW, there was some bugs on IE, forcing you to enclose select and focus functions into a setTimeout, like that :
setTimeout(function(){$("#username").select()}, 1);
Upvotes: 3