[thelist] Autofocus usability issues tackled

Lee kowalkowski lee.kowalkowski at googlemail.com
Fri Oct 13 05:23:11 CDT 2006


On 09/10/06, Christian Heilmann <codepo8 at gmail.com> wrote:
> I have a pet peeve, which is web sites that automatically focus a
> certain form field when the page has loaded. I understand the logic of
> it, but more than once I found myself having already typed in half the
> email - or, even worse, my password before being forcefully sent back
> to the email field and delete what I entered there.

This is the unfortunate thing about using event-driven design when
it's not appropriate.  The onload event is not the right choice for
setting form field focus, that is the problem, because of the issues
you highlight.  Some documents can take ages to load, and a few never
completely load (shame on them though).

Some sites still insist on this.  The number of times I have been
halfway through my password and suddenly it's being appended to my
username for all to see.

Google mail tries to be a little smarter, once the page has loaded, it
sets focus on username, unless there's something in it, then it sets
focus on the password field - but hold your horses smartie-pants! -
I'm still in the middle of typing by bleeding username!  Kowalkowski's
not that easy to type with a drink in one hand, now I'm entering the
rest of it into the password field!  Grr...

My preferred solution is to include a script element immediately (or
as soon as possible) after the field that requires focus:

<script src="focus.js" type="text/javascript"></script>

User agents must execute this script immediately, because it may
containt things like document.write which must be executed before the
document is parsed.

The script just sets focus on the desired field, which can be
identified by classname or other consistent mechanism/rule (e.g.
always first field on the first form - depends on your requirements),
preferably in a reusable way - one short script, normally cached.

The user doesn't get the chance to enter anything before focus is given.

-- 
LK



More information about the thelist mailing list