Forms [Robin’s HTML 4.0 Conformance Test]
Author: Lionheart, Robin
Description: Test your Web browser’s support for HTML 4.0 forms. Part of Robin’s HTML 4.0 Conformance Test.

# Forms (§17)

## Fieldsets and tab indexes

- `<fieldset>` groups related form controls into sections.
- `<legend>` assigns a caption to a `<fieldset>`.

- `tabindex` lets you set the order in which hyperlinks and form controls gain focus.

XHTML 2.0: The W3C is discussing replacing `tabindex` in XHTML 2.0 with common `nextfocus` and `prevfocus` attributes, which contain an `id` reference of the next element to be activated.

### Example:

The controls are numbered according to their tab order. Tabbing forward from "1:" should take you to "2:", and so forth.

<form action="#test">
<fieldset>
<legend>Tab Index</legend>
<p>The focus should move through the following controls in numerical order.</p>
<table>
<tr>
<td>1: <td><input tabindex=1 value="One" size=6>
<td>3: <td><input tabindex=3 value="Three" size=6>
<td>7: <td><input tabindex=7 value="Seven" size=6>
<tr>
<td>2: <td><input tabindex=2 value="Two" size=6>
<td>4: <td><input tabindex=4 value="Four" size=6>
<td>6: <td><input tabindex=6 value="Six" size=6>
</table>
<table>
<tr>
<td>5:
<td>
<select tabindex=5>
<option selected>Five
</select>
<tr>
<td>9:
<td><textarea rows=2 cols=3 tabindex=9>Nine</textarea>
</table>
8: <button type="button" tabindex=8>Eight</button>
</fieldset>
</form>

#### Your Web browser renders it like this:

Tab Index

The focus should move through the following controls in numerical order.

1: |  | 3: |  | 7: |
2: |  | 4: |  | 6: |

5: |
9: | Nine

8:

## Labels and access keys

`<label>` associates its contents with a form control. In a Web browser, selecting a label could give its corresponding control focus.

The `accesskey` attribute assigns a key to give focus to an element.

XHTML 2.0: The W3C is discussing replacing `accesskey` in XHTML 2.0 with a common `access` attribute to assign an access name that will activate an element. `accesskey` is too associated with particular user interfaces. Instead of keystrokes, `access` associate words with elements which users may select them by other means, such as selecting them from a menu or speaking an access name into a microphone.

### Example:

Selecting (ex. clicking on) the following labels should activate the corresponding field. The highlighted letters are designated as shortcut keys for the field, which may be supported in different ways by different Web browsers.

For example, in Internet Explorer 4.0— and Netscape 6.0— for Windows, `Alt‐U` will select the “User name:” field.

<form action="#test">
<fieldset>
<legend accesskey="L"><strong>L</strong>abels and Access Keys</legend>
<p>Selecting the following labels should activate the corresponding form control. You may also be able to use the highlighted letters to select a form control.</p>
<label accesskey="U"><strong>U</strong>ser name: <input type="text" name="uname" size=40></label><br>
<label for="email"><strong>E</strong>&#8208;mail: <input id="email" accesskey="E" type="text" name="email" size=40></label><br>
<p>Sex:
<label accesskey="M"><input type="radio" name="sex" value="male"><strong>M</strong>ale</label><br>
<input id="female" accesskey="F" type="radio" name="sex" value="female"><label for="female"><strong>F</strong>emale</label></p>
<p><label accesskey="G"><strong>G</strong>ender:
<select size=2>
<option>Male
<option>Female
</select></label></p>
<p><label for="honorific" accesskey="H"><strong>H</strong>onorific:</label>
<select id="honorific" size=3>
<option>Mr.
<option>Ms.
<option>Miss
<option>Mrs.
<option>Dr.
</select></p>
<p>Where did you hear about us? (check all that apply)<br>
<label accesskey="S"><input type="checkbox" name="where" value="search"><strong>S</strong>earch engine</label>
<label><input type="checkbox" accesskey="O" name="where" value="other"><strong>O</strong>ther</label></p>
<p><label accesskey="W">If other, <strong>w</strong>here?<br>
<textarea rows=2 cols=40></textarea></label></p>
<p><label><strong>C</strong>omments:<br>
<textarea rows=2 cols=40 accesskey="C"></textarea></label></p>
</fieldset>
</form>

#### Your Web browser renders it like this:

Labels and Access Keys

Selecting the following labels should activate the corresponding form control. You may also be able to use the highlighted letters to select a form control.

User name:
E‐mail:

Sex: Male Female

Gender:

Honorific:

Where did you hear about us? (check all that apply)
Search engine Other

If other, where?

Comments:

Related Mozilla bug reports: Accesskey-XUL, Legend-Accesskey, Fieldset-Eats-Spaces, Checkbox-Accesskey.

Related Internet Explorer bug reports: Channel9 Wiki: Internet Explorer Standards Support.

## Buttons

`<button>` allows push button controls to contain any sort of markup, not just simple text.

### Example:

This form has buttons of each type. The change message buttons change the message field when selected, if your Web browser supports ECMAScript. If you type over the text in the message field, Reset should restore the message to its default. Submitting the form should reload this page.

<form action="#test">
<fieldset>
<legend>Buttons</legend>
<p>Message: <input id="message" type="text" name="message" size="40" value="Change this then try Reset."></p>
<p>Change message:
<button type="button" onclick="document .getElementById('message') .setAttribute('value', 'Take it easy!')">Get Some R&amp;R</button>
<button type="button" onclick="document .getElementById('message') .setAttribute('value', 'Have a nice day!')">Smile <img src="/images/smiley/smile.png" alt=":-)"></button>
<button type="button" onclick="document .getElementById('message') .setAttribute('value', 'Lather, rinse, repeat')">
<ul>
<li>Lather
<li>Rinse
<li>Repeat
</ul>
</button></p>
<p><button type="submit">Submit</button>
<button type="reset">Reset</button></p>
</fieldset>
</form>

#### Your Web browser renders it like this:

Buttons

Message:

Change message:

## Option groups

`<optgroup>` groups into sections the `<option>` elements in a `<select>` control. A Web browser could add dividers or headings to the drop‐down list, or collapse them into cascading drop‐down menus.

The `label` attribute on the `<optgroup>` and `<option>` elements provides a name to use within grouped selection menus.

### Example:

<form action="#test">
<fieldset>
<legend>Option Groups</legend>
<p>Browser of Choice:
<select name="agent">
<optgroup label="Microsoft Internet Explorer">
<option label="5.x–6.x" value="ie5">Microsoft Internet Explorer 5.x&ndash;6.x
<option label="4.x" value="ie4">Microsoft Internet Explorer 4.x
<option label="3.0 or lower" value="ie3">Microsoft Internet Explorer 3.0 or lower
</optgroup>
<optgroup label="Mozilla">
<option label="Firefox" value="fox">Mozilla Firefox
<option value="moz" selected>Mozilla
</optgroup>
<optgroup label="Netscape">
<option label="6.x" value="n6">Netscape 6.x
<option label="4.x" value="n4">Netscape 4.x
<option label="3.x or lower" value="n3">Netscape 3.x or lower
</optgroup>
<option value="op">Opera
<option value="safari">Safari
<option value="omniweb">OmniWeb
<option value="icab">iCab
<option value="lynx">Lynx
<option value="other">Other
</select></p>
</fieldset>
</form>

#### Your Web browser renders it like this:

Option Groups

Browser of Choice:

Related Mozilla bug reports: Option-Label.

Related Internet Explorer bug reports: Channel9 Wiki: Internet Explorer Standards Support.

### Example:

The previous example again, but with `size="10"` set on the `<select>` element.

#### Your Web browser renders it like this:

Option Groups

Browser of Choice:

Related Mozilla bug reports: Option-Label.

Related Internet Explorer bug reports: Channel9 Wiki: Internet Explorer Standards Support.

## Disabled and Read‐only

- `disabled` prevents a form control from receiving focus or accepting input. Disabled controls do not send data when the form is submitted.
- `readonly` prohibits changes to a form control. Read‐only controls still send data when the form is submitted.

Though HTML 4.0’s definition of `readonly` implies that checkboxes and radio buttons may be set read‐only (and no errata has changed the definition), `readonly` is meant only for `text` or `password`.

In a working draft of the Web Forms 2.0 standard, WHAT Working Group clarifies, Specifically, it does not apply to radio buttons, check boxes, file upload fields, select elements, or any of the button types; the interface concept of readonly values does not apply to button‐like interfaces. Also, the Document Object Model level 2 standard describes the associated `readOnly` method as Relevant only when `type` has the value “`text`” or “`password`”.

(Opera 5.x supported read‐only checkboxes and radio buttons, but removed support for them in version 6.0.)

### Example:

<form action="#test">
<fieldset>
<legend>Disabled and Read&#8208;Only</legend>
<fieldset>
<legend>Normal</legend>
<p>These controls should be fully functional.</p>
<input type="text" value="Changeable" size=14>
<input type="checkbox" checked>
<input type="radio" name="yn1">Yes <input type="radio" name="yn1" checked>No
<br>
<textarea rows=3 cols=20>Can edit this.</textarea>
<select size=3>
<option>One
<option selected>Two
<option>Three
</select>
</fieldset>
<fieldset>
<legend>Disabled</legend>
<p>You should not be able to select these controls.</p>
<input type="text" value="Unselectable" size=14 disabled>
<input type="checkbox" checked disabled>
<input type="radio" name="yn3" disabled>Yes <input type="radio" name="yn3" checked disabled>No
<br>
<textarea rows=3 cols=20 disabled>Can't touch this.</textarea>
<select size=3 disabled>
<option>One
<option selected>Two
<option>Three
</select>
<input type="reset" disabled>
<button type="reset" disabled>Undo changes</button>
<br>
<p>You should be able to select only option A or B.</p>
<select size=7>
<optgroup label="Pass">
<option>A
<option>B
<option disabled>C (unavailable)
</optgroup>
<optgroup label="Fail (unavailable)" disabled>
<option>D
<option>F
</optgroup>
</select>
</fieldset>
<fieldset>
<legend>Read&#8208;Only</legend>
<p>You should be able to select but not change these controls.</p>
<input type="text" value="Unchangeable" size=14 readonly>
<br>
<textarea rows=3 cols=20 readonly>Can't edit this.</textarea>
</fieldset>
</fieldset>
</form>

#### Your Web browser renders it like this:

Disabled and Read‐Only
Normal

These controls should be fully functional.

Yes No
Can edit this.
Disabled

You should not be able to select these controls.

Yes No
Can't touch this.

You should be able to select only option A or B.

Read‐Only

You should be able to select but not change these controls.

Can't edit this.

## Your Browser

Your Web browser identified itself as `Wget/1.11.4` when it requested this page.