One of the things that can bite you is if you are using .onmousedown
as your user interaction; when you do that, and then an attempt is immediately made to select a field, it won't happen, because the mouse is being held down on something else. So change to .onmouseup
and viola, now focus()
works, because the mouse is in an un-clicked state when the attempt to change focus is made.