The Wayback Machine - https://web.archive.org/web/20090531145832/http://www.webreference.com:80/html/tutorial13/19.html


spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / html / tutorials / 13 / 19

index123456789101112131415161718192021exercises1

Tutorial 13: Giving Form to Forms

Developer News
Rails 3 Gets Supersized With Merb
SpringSource, Hyperic Merge for App Management
Get Ready for Windows 7 'Release Candidate'

Control labels

As you have seen in the various examples in the previous pages, most of the time you will supply some information along with your controls indicating what their use is. This information is usually in the way of labels that contain the control's function. In HTML 4.0, you can use the LABEL element to indicate that a part of your document is actually a label for a form control. This is useful in a number of ways, for instance if a user clicks on a label, the focus is usually given to the control. This is especially useful for checkboxes and radio buttons, which tend to be tiny, where a label will offer more of an area for the user to click on.

The LABEL element

Context:
Can only appear inside FORM elements.
Contents:
Can contain inline elements and text, and at most one form control.
Tags:
Both start-tag and end-tag are required.

Attributes for the LABEL element

FOR (ID reference)
The value of this attribute is the value of the ID attribute of the control that this label corresponds to.
Accessibility key attribute
Identifier and classification attributes
Language information attributes
Title attribute
Inline style information attribute
Intrinsic event handler attributes

The easiest way to use the LABEL element is to enclose the control it refers to inside it. This is not always practical, in which case you can give the control an ID attribute and specify it in the FOR attribute of the label.

LABEL is supported by Internet Explorer since version 4.0, but the only syntax recognized is that in which you use FOR to indicate the control the label refers to; putting the element inside the LABEL doesn't work in IE 4.0 or 5.0. Navigator does not support LABEL, but Mozilla does, so we'll probably see it when Navigator 5.0 comes out this summer.

The following example illustrates the use of LABEL with text boxes and radio buttons.

<FORM ACTION="/cgi-bin/html/formdump.cgi" 
      METHOD="GET" ENCTYPE="application/x-www-form-urlencoded">
<P>
<LABEL FOR="fn">First Name:</LABEL>
<INPUT ID="fn" TYPE="text" NAME="firstname" SIZE="10">
<LABEL FOR="ln">Last Name:</LABEL>
<INPUT ID="ln" TYPE="text" NAME="lastname" SIZE="10">

<P>Gender:
<LABEL FOR="gm">Male</LABEL>
<INPUT TYPE="radio" NAME="gender" VALUE="male" ID="gm">
<LABEL FOR="fm">Female</LABEL>
<INPUT TYPE="radio" NAME="gender" VALUE="female" ID="fm">

<INPUT TYPE="submit">
</FORM>

Gender:

index123456789101112131415161718192021exercises1

Produced by Stephanos Piperoglou

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info
Copyright 2009 WebMediaBrands Inc. All Rights Reserved.

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Getting Started with URL Rewriting with Apache · Kicking the Tires on Your Next CMS · User Personalization with PHP: The Final Scripts
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Write SQL Code for MySQL Using HeidiSQL 4 · Government Mobility and Why It's Not an Oxymoron · Site Building with Photoshop and Dreamweaver

URL: http://www.webreference.com/html/tutorial13/19.html

Created: May 28, 1998
Revised: February 25, 1999

Morty Proxy This is a proxified and sanitized view of the page, visit original site.