- type=text (the default)
- A single line text field whose visible size can be set using the size attribute, e.g. size=40
for a 40 character wide field. Users should be able to type more than
this limit though with the text scrolling through the field to keep the
input cursor in view. You can enforce an upper limit on the number of
characters that can be entered with the maxlength attribute. The name attribute is used to name the field,
while the value attribute can be used
to initialize the text string shown in the field when the document is
first loaded.
<input type=text size=40 name=user value="your name">
- type=password
- This is like type=text, but echoes characters using a character
like * to hide the text from prying eyes when entering passwords.
You can use size and
maxlength attributes to control
the visible and maximum length exactly as per
regular text fields.
<input type=password size=12 name=pw>
- type=checkbox
- Used for simple Boolean attributes, or for attributes that can take
multiple values at the same time. The latter is represented by several
checkbox fields with the same name and
a different value attribute. Each checked
checkbox generates a separate name/value pair in the submitted data, even
if this results in duplicate names. Use the
checked attribute to initialize
the checkbox to its checked state.
<input type=checkbox checked name=uscitizen value=yes>
- type=radio
- Used for attributes which can take a single value from a set of
alternatives. Each radio button field in the group should be given the
same name. Radio buttons require an explicit
value attribute. Only the checked radio
button in the group generates a name/value pair in the submitted data. One
radio button in each group should be initially checked using the
checked attribute.
<input type=radio name=age value="0-12">
<input type=radio name=age value="13-17">
<input type=radio name=age value="18-25">
<input type=radio name=age value="26-35" checked>
<input type=radio name=age value="36-">
- type=submit
- This defines a button that users can click to submit the form's
contents to the server. The button's label is set from the
value attribute. If the
name
attribute is given then the submit button's name/value pair will be
included in the submitted data. You can include several submit buttons
in the form. See type=image for graphical submit buttons.
<input type=submit value="Party on ...">
- type=image
- This is used for graphical submit buttons rendered by an image
rather than a text string. The URL for the image is specified with the
src attribute. The image alignment can
be specified with the align
attribute. In this respect, graphical submit buttons are treated
identically to IMG elements, so you can
set align to left, right, top, middle or bottom. The x and y values of
the location clicked are passed to the server: In the submitted data,
image fields are included as two name/value pairs. The names are derived
by taking the name of the field and appending ".x" for the x value, and
".y" for the y value.
<p>Now choose a point on the map:
<input type=image name=point src="map.gif">
Note: image fields typically cause problems for text-only and
speech-based user agents!
- type=reset
- This defines a button that users can click to reset form fields
to their initial state when the document was first loaded. You can
set the label by providing a value
attribute. Reset buttons are never sent as part of the form's contents.
<input type=reset value="Start over ...">
- type=file
- This provides a means for users to attach a file to the form's
contents. It is generally rendered by text field and an associated
button which when clicked invokes a file browser to select a file
name. The file name can also be entered directly in the text field.
Just like type=text you can use the size
attribute to set the visible width of this field in average character
widths. You can set an upper limit to the length of file names using the
maxlength attribute. Some user agents
support the ability to restrict the kinds of files to those
matching a comma separated list of MIME content types given with
the ACCEPT attribute e.g. accept="image/*"
restricts files to images. Further information can be found in
RFC 1867.
<input type=file name=photo size=20 accept="image/*">
- type=hidden
- These fields should not be rendered and provide a means for servers
to store state information with a form. This will be passed back to the
server when the form is submitted, using the name/value pair defined by
the corresponding attributes. This is a work around for the statelessness
of HTTP. Another approach is to use HTTP "Cookies".
<input type=hidden name=customerid value="c2415-345-8563">