Focusing from an anchor link, esp. on form fields

Hi,

It is currently not possible as far as I can tell to give the focus to a
specific form field by following a link; this would seem like a handy
feature to enable, e.g. to allow the user to correct a mistake.

For instance with a form like:
        <p><label for='email' id='emaillabel'>Email:</label>
        <input type='text' id='email' name='email'></p>
it would be useful if following a link to #emaillabel or #email would
give the focus to the input field; this would allow to write an error
message à la
        <p class='error'>The <a href="#email">email address</a> is not
        valid.</p>

More generally, it looks like the behavior of browsers on focus after
following an anchor varies from one browser to another, as Florent
Verschelde reported on the blog post I made on this topic:
> At least in FF4, this is broader than just input elements or form fields. Try to do the same with any focusable element (a link or Whatever), and the element won’t get the focus either.
> 
> See this quick test page:
> http://covertprestige.info/temp/focus-target.html
> 
> Elements do get the :target state, including the first paragraph which cannot gain focus, but they don’t get the focus. Regarding focus, the behavior is different from one browser to another:
> 
> - Firefox takes the focus away from the clicked link, but doesn’t give it to any element. BUT, the target element becomes the starting point for keyboard navigation so the next keystroke on TAB gives focus to the focusable element right after the target element.
> 
> - Safari and Chrome keep the focus on the clicked link.
http://people.w3.org/~dom/archives/2010/11/activating-html-forms-fields-through-a-link/#comment-72062

Maybe there is room at least for harmonization on the focus behavior,
and at best for providing a better way to guide the user in form fields?

I didn't see anything on this topic in
http://dev.w3.org/html5/spec/editing.html#focus so I thought I would
bring this here; there may be good reasons why focusing based on links
is not a good idea, in which case I'd be happy to learn about it.

Dom

Received on Wednesday, 24 November 2010 10:10:42 UTC