Text
Box
The <input> tag is used to create a text box on
the page, with the type attribute set to "text". The
code for this would be: <input type="text">. Note that the <input>
tag is not closed.
Additional attributes to include are:
- name - This is the variable name assigned to the data;
the script needs this information
- id - This value binds the field to other elements
for use in the script
- value - If you want some information to appear in
the text box when the page loads, set that as the value for this attribute
- size - The width of the box, in characters
- maxlength - The maximum number of characters accepted
by the box
<label for="fname">First
Name: </label><input type="text" name="fname" id="fname"
size="15" maxlength="20" value="Enter Name">
- The above example would create a text box 15 characters wide, that
accepts up to 20 characters
- The code would render as:
When dealing with text fields, be aware of cross-browser
differences in their size. Netscape 4.x makes these fields very wide,
so test in that browser to make sure the size is acceptable and does
not break your page layout.
Text Area Box
The <textarea> tag is used to create a textarea
box on the page. Unlike the <input> tag, this tag needs to be
closed.
Attributes for the <textarea> tag are:
- name - This is the variable name assigned to the data;
the script needs this information
- rows - The height of the box in rows
- cols - The width of the box in characters
- wrap - Like noshade and nowrap, the wrap attribute
has no value assigned to it - if included, lines are automatically
wrapped within the margins
<label for="comments">Comments:
</label><textarea name="comments" id="comments" rows="8"
cols="30" wrap></textarea>
- The above example would create a textarea box 30 characters wide
and 8 rows tall
- The code would render as:
Radio Buttons
The <input> tag is also used for radio buttons and
check boxes. For radio buttons, the type attribute
is set to "radio". Since you use the <input> tag, it does not
need to be closed. Radio buttons should only be used for data in which
one item is selected.
Attributes for the <input> tag are:
- name - This is the variable name assigned to the
data; the script needs this information. Be sure to use the same
name for all the radio buttons in the same group
- value - The data that will be sent to the server
if that radio button is selected
- checked - Like wrap, this attribute has no value
assigned to it - if included, the radio button is selected by default.
Apply this attribute to only one of the radio buttons
Color: Blue: <input type="radio" name="color"
value="blue">
Red: <input type="radio" name="color" value="red" checked>
Yellow: <input type="radio" name="color" value="yellow">
- The above example would create three radio buttons, with the middle
radio box 'checked' (selected by default)
- The code would render as:
Check Boxes
To create check boxes, the type attribute
is set to "checkbox". Use checkboxes for data in which multiple items
can be selected.
Attributes for the <input> tag are:
- name - This is the variable name assigned to the data;
the script needs this information. Be sure to use the same name for
all the checkboxes in the same group
- value - The data that will be sent to the server if
that checkbox is selected
- checked - Like wrap, this attribute has no value assigned
to it - if included, the checkbox is selected by default. This attribute
can be assigned to as many checkboxes as you want
Sizes: Small: <input type="checkbox" name="size" value="small">
Medium: <input type="checkbox" name="size" value="medium" checked>
Large: <input type="checkbox" name="size" value="large" checked>
- The above example would create three checkboxes, with the second
and third checkboxes 'checked' (selected by default)
- The code would render as:
Menus
The <select> </select> tags are used with
<option></option> tags to create the menu list items. Menus
are good to use if you are dealing with more than a few items because
they can help conserve screen space.
Attributes the <select> tag are:
- name - This is the variable name assigned to the data;
the script needs this information
- size - The value assigned to this attribute is the
height of the menu in lines
- multiple - Like checked, this attribute has no value
assigned to it - if included, multiple selections are possible in
the menu
- Within the <select> tags are <option> </option>
tags, one for each item in the menu
Attributes the the <option> tags are:
- value - The data that will be sent to the server if
the menu item is selected
- selected - Like checked, this attribute has no value
assigned to it - if included, that item is selected by default. Only
one item can be selected
Color:
<select name="color" size="3" multiple>
<option value="blue">Blue</option>
<option value="red" selected>Red</option>
<option value="yellow">Yellow</option>
</select>
- The above example would create a menu with three choices visible.
The middle choice would be selected by default. Multiple selections
would be possible.
- The code would render as:
Changing the code to remove the size
and multiple attributes renders as:
Create
an Order Form
- Create a new html file and save it as form2.html.
- Recreate the form shown in the link above. You will need to use
tables (the table is 600 pixels wide).
- Be sure to assign name attributes to all the
fields and buttons/boxes.
- When you are finished, view the file in the browser.