<label> & <input> tags

M

Moosus Gracius

Quick Question,

Can you nest input tags insde of label tags and do away with the for
attribute?

ie:
<p><label>Comments:<textarea name="textareaName" rows="4"
cols="40"></textarea></label></p>

or do I need to place them all inline

ie:
<p><label for="comments">Comments:</label><textarea
name="textareaName" rows="4" cols="40" id="comments"></textarea></p>

Cheers
moosus
 
T

Toby Inkster

Moosus said:
Can you nest input tags insde of label tags and do away with the for
attribute?
<p><label>Comments:<textarea name="textareaName" rows="4"
cols="40"></textarea></label></p>

Yes, but Interner Explorer doesn't support this. (Not sure if it's been
fixed in IE7.)
 
J

Jukka K. Korpela

Scripsit Toby Inkster:
Yes, but Interner Explorer doesn't support this. (Not sure if it's
been fixed in IE7.)

There's no specific support _required_ for the markup. The <label> markup is
declarative: it just specifies a logical relationship between some text and
some form field.

But I guess you mean the feature that by clicking on the label text, as
specified by the <label> markup, the form field can be focused on. This
feature exists in IE when "explicit" association with for and id attributes
has been established but not when "implicit" association (by nesting the
field inside the <label> element - rather illogical if you ask me!) is used.
This has been changed in IE 7, i.e. it recognizes the "implicit" association
too.

The feature is not particularly useful for <textarea>, since you can just as
well or better click on the area itself. It is much more useful for radio
buttons and checkboxes, which are rather small, creating a problem if you
are motorically challenged.

On the other hand, the explicit association has worked for a long time and
keeps working, and it is a more logical approach. The only drawbacks are
that you need a little more markup and you need to invent unique identifiers
for the fields.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top