views:

149

answers:

6

If I have a form that is the main part of a page's content, will assigning focus to the first form field via JavaScript on page load have any negative effects on accessibility?

A: 

will assigning focus to the first form field via JavaScript on page load have any negative effects on accessibility?

I can't think of any. In between fields might irritate whatever assistive software a user might be running, but the first field - hardly. I have no experience with braille and similar clients.

Seeing as even Google do it on their front page, I don't think it can be that big a deal either way.

Pekka
Just because someone uses a screen reader doesn't mean they don't use JavaScript. The page is rendered in the browser complete with JavaScript, then a model of the page is handed off to the screen reader. When the page is updated with JavaScript those updates are sent to the model of the page the screen reader works with.
Jared
A: 

I wouldn't say so. A screenreader will probably not even notice this since it doesn't interpret the JavaScript on the page.

Another user which has a "normal" browser will get the advantage of having the cursor already at the right place which facilitates the navigation by using just the keyboard.

Juri
As a screen reader user this is not correct. The browser runs the JavaScript then returns a model of the page to the screen reader. This means you can easily be placed in a form field with no context of what it is or why your there.
Jared
Very interesting! - Just goes to show what a useful community this is. I've been a web developer for about 12 years or so and I would have given exactly the same answer as Juri. I had no idea that screen readers worked in this way now days. I will be having a fresh look at accessibility in the near future. Can you detect a screen reader and perhaps focus a different, more useful part of the page instead?
meouw
There's no way to detect weather a screen reader is running from with in a browser that i know of. If you want to have a look at ways to help screen reader users by providing extra information take a look at http://www.w3.org/TR/2008/WD-wai-aria-20080204/ Not sure if this is the newest version but it is the version linked to when Google announced they had put ARIA support into Google reader.
Jared
Interesting. Thx @Jared. Didn't know that actually. I though screen readers just interpret the HTML and completely ignore JavaScript.
Juri
+1  A: 

I wouldn't say so, fragments are an ingredient of HTTP and they set the focus of an *html page..

Viktor Klang
Come again - what "fragments"?
Jørn Schou-Rode
fragments = #TextAtTheEndOfAURL
jball
See http://en.wikipedia.org/wiki/Fragment_identifier for more info.
jball
+4  A: 

The short answer is no it doesn't make things inaccessible but it can make it confusing. The longer answer follows. Will your users know that there going to a page with a form, and does there need to be any descriptive text you should read before filling out the form? I'm a screen reader user and it can be annoying having focused put in random fields. It's clear why your focus winds up in the Google search box so that doesn't bother me. If my focus were automatically placed in the answer edit field every time I viewed a question on Stackoverflow I would be annoyed since I'd have to force my screen reader to navigate away from the form field and to the top of the page.

Jared
A: 

A lot of sites will do this, google is a good example, the only issue is when you are typing something into the address bar, or into the search input in your browser, the action of focusing the form field tends to steal focus from where you are typing. It's a small nuisance.

Tracker1
+1  A: 

It might a bit, if we've got a keyboard user (either using a screen-reader, or just a habitual keyboard user) who's expecting to be navigating the links at the top of the page on first Tab press. For screen readers, you could also consider adding WAI-ARIA to add directions if users who don't expect to be dumped into the middle of a form.

If it's much more likely that the user's going to be wanting to type in the field straight away, then I think the autofocus is worth it. But for the reason above I wouldn't use it on every page with an input field.

If you do autofocus, make sure to do it right away, in a script as soon as possible following the input element, or in future using the HTML5 autofocus attribute. Don't do it as late as window.onload. It's annoying to have clicked the focus elsewhere only to have the document belatedly finish loading and steal the focus onto another element as you type.

bobince
Excellent point about when to implement the autofocus.
David Kolar