Chris W. Parker schrieb:
> On Tuesday, November 14, 2006 7:35 AM Klaus Hartl <> said:
> 
>> Most browsers don't focus a field from
>> a link pointing to the field's id, so I usually add a click event to
>> explicitly focus the form element. The field to focus is simply read
>> from the link's href...
> 
> Unless I'm misunderstanding your implementation, your problem is that
> you're using the wrong tag. Don't use an anchor+js to link an error
> message with its field. You should be using <label> instead.
> 
> <label for="first_name">This field cannot be empty.</label>
> <input id="first_name" type="text" size="20"/>
> 
> You can have as many <label>s as you want pointing to the same field.
> This will make the browser put focus is the field where
> name="id_of_form_field".
> 
> 
> <div id="errors">
>  <label for="first_name">Error with First Name</label>
> </div>
> 
> <form ...>
>  <label id="first_name">First Name</label>
>  <input id="first_name" .../>
> </form>
> 
> Both of the above labels will put focus in the first_name field when
> clicked. Use CSS to style the label(s) however you want.
> 
> 
> Chris.

Hi Chris,

yes, I know how labels work. However when I have a list on top of the 
form, which is quite far away from the actual fields (outside the form) 
I tend(ed) to use an anchor instead. But you are right, why not simply 
using labels there as well! :-) I wonder how browser behave when the 
field is out of the borders of the viewport... will they scroll down? 
Not sure...

Safari still doesn't focus the corresponding field when clicking on a 
label, so I will add a click event in any case.


-- Klaus

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to