I've been asked to add this feature on forms many times, and on very simple, quick-to-load forms like a login form, then fair enough, it saves someone a click or a press of the tab key, and saving someone a click has to be A Good Thing™, right? It means they can start typing straight away, right?
Wrong. For more complex forms - for instance, if you have a WYSIWYG component in the form which takes a while to initialise - setting focus to the first element onload() can actually make the form LESS usable, not more.
If you set an onload event on the document, then it doesn't fire until all of the referenced elements within the document have finished loading. When you have a lot of elements - particularly common with WYSIWYGs - then it's quite possible for the referenced elements to take several seconds to finish loading after the form has already appeared.
So the sequence of events goes like this -
- Form appears
- User starts typing in the first field
- User completes this field, moves onto the second and starts typing
- ...repeat step 3 an arbitrary number of times, until...
- referenced elements like scripts, hit trackers, banner ads, captchas, WYSIWYG components finally all finish loading
- THEN the onload() event fires
- focus "helpfully" gets set to the first form field, usually while the user is in the middle of typing in a large textarea and - crucially - looking at their keyboard, not the screen
- user finishes what they're typing and looks up
- user realises that for the last 30 seconds or so, they've been typing into the first field, not the big textarea that they thought they were typing in.
- optional Brucie Bonus - As the first field on a form is nearly always fairly short, the maxlength has been hit quite early on, but the user didn't realise this because they were looking at the keyboard. Hence, user realises that the last X words they typed have just disappeared.
- user swears loudly and curses this damn web system that was supposed to solve all their problems but has just given them a load of new ones.
I know, I know, it's a simple thing, but it drives me completely incandescent with frustration when I realise that I've lost the big long chunk of text that I was typing because the focus has shifted.
It's almost as bad as when someone starts an IM chat with you and the window pops up and starts accepting input without you noticing, and then you suddenly realise you've accidentally sent your Mum a foul-mouthed tirade that was intended for something entirely different...