form tag
button tag
input tag
optgroup tag
select tag
textarea tag
TAG: option
<option> ... </option>
The
option
tag is used to insert one item in a pull-down form control. You may repeat this tag an unlimited number of times in a pull-down list. (For example, you could list all fifty states.) By default, when an item is chosen, the value that is added to the contents of the
form
is the text that appears immediately after the opening
option
tag. However, you can specify a different value by using the
value
attribute.
This tag must be placed between the opening and closing
select
tags. The order of the
option
tags determines the default order of the list. However, you can use the
selected
attribute to specify one item always to appear at the top of the list.
In general, a pull-down list should be treated as a menu. It is recommended that the text for each item in the list be short, such as one or two words. A long text can be far too unwieldy to read and will probably annoy most users.
The separate closing tag is mandatory.
Attributes and Events
class
dir
id
lang
onclick
ondblclick
onkeydown
onkeypress
onkeyup
onmousedown
onmousemove
onmouseout
onmouseover
onmouseup
style
title
disabled
The
disabled
attribute is a Boolean value that, if present, prevents the form control (field) from functioning. In some browsers, the control (field) will appear to be greyed out.
label
The
label
attribute is used to create a short text version of the text that appears after the opening
option
tag.
selected
The
selected
attribute is used to specify which one item in the pull-down will appear at the top of the list. Some browsers highlight the selected item. The default is that the list is in the same order as the
option
tags and there is no highlighting
value
The
value
attribute is used when you need to set a different value for the item in the pull-down that what is listed in the
option
tag.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="eng">
<head>
<title>DevGuru XHTML option Tag Example</title>
</head>
<body>
<select size="2">
Gold Fish
<br />
<
option selected
>Bubble-Eye<
/option
>
<
option
>Comet<
/option
>
<
option
>Common<
/option
>
<
option
>Oranda<
/option
>
<
option
>Pearl Scale<
/option
>
<
option
>Ranchu<
/option
>
<
option
>Ryukin<
/option
>
</select>
Output:
Gold Fish
Bubble-Eye
Comet
Common
Oranda
Pearl Scale
Ranchu
Ryukin
Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information