i am dustin diaz

a JavaScriptr...

boosh.

don't worry about it.

Focus the user: Narrow the options

I'm no usability guru, but I do take note in patterns that help assist the user in any possible situation. The most common situation on the web is filling out forms. They are also the most abused. In this article I hope to provide some simple (unobtrusive) JavaScript to help aid in form usability as well as making the form more accessible.

Focus the Fieldset

Unfortunately the fieldset element does not support the .focus() method. On the contrary, input, button, select, textarea elements do support .focus(). As most of you should already know, it is best to wrap grouped form elements inside a fieldset. So with this in mind, if your form has multiple fieldsets, it would be optimal to focus the fieldset.

Focus the element

Now that we've decided to focus our group, as an additional user-feedback layer, we are going to focus the individual element we've landed on. This way, there is no way in God's forbidden land anyone can get lost on this webpage (that is - of course - if they are not blind).

Putting it all together

With these two embedded layers of interaction and without proliferating our xHTML document with JavaScript, I introduce to you the Focus the User Form. It's easy to implement, does not take a bite out of accessibility, and conveys a message of simplity.

this is who i am

Hi, my name is Dustin Diaz and I'm an Engineer @ObviousCorp. Previously @Twitter, @Google, and @Yahoo, author of Strobist® Info co-author of JavaScript Design Patterns, co-creator of the Ender JavaScript Framework, a Photographer, and an amateur Mixologist. This is my website. Welcome!

On this site I write about JavaScript. You can also follow along with my open-source work on Github.

This site is optimized and works best in Microsoft Internet Explorer 6.