FORM, INPUT, TEXTAREA, SELECT
FORM tag is among the tags that its true usage and implementation is covered in a more advanced
course (Multimedia Instructional Design II). Nonetheless, a wide range of capabilities of
FORM and its associated tags INPUT, SELECT, and TEXTAREA can be discussed within this course
as well.
In general, <FORM> ... </FORM> tags are used to wrap the elements of a Web-based
form. The form can contain interface elements such as text fields, buttons, checkboxes,
radio buttons, and selection lists that let users enter text and make choices. Each interface
element in the form must be defined with an appropriate tag. These tags are INPUT, SELECT,
and TEXTAREA. All elements in the form must be defined between the <FORM> and </FORM>
tags. As well as user input elements, the form can contain other elements such as texts, images,
paragraphs, tables, and so on.
When the form is displayed in a web browser, the user can fill it out by making choices and
entering text using the interface elements, and then submit the form by clicking a "Submit" button.
Several kinds of form elements can be defined using the
INPUT tag, which uses the TYPE attribute to indicate the type of element, such as button,
checkbox, and so on. Two other kinds of interface elements you can put in a form are
selection lists and text areas. Selection lists act as menus and are defined with the SELECT tag.
Multi-line text-entry fields are defined with the TEXTAREA tag.
To enable the form to process the data that the user enters, it must have a "Submit" button,
which is a button defined by an INPUT tag with TYPE="SUBMIT" (there are other ways too).
Instead of starting with the formal definition of FORM tag, we begin
by defining the basic formats of SELECT, INPUT
and TEXTAREA tags and through use of examples illustrate different
usages of these tags. The only point that you need to consider is that these tags must be
within <FORM> ... </FORM> tags which we define later in this document.
INPUT
The INPUT tag defines a form element that can receive user input. The TYPE attribute determines
the specific sort of form element to be created. There is a large number of attributes associated
with INPUT
elements. Following is an explanation of the attributes of the basic format of INPUT.
<INPUT
TYPE=type
ALIGN=top|middle|bottom|left|right
CHECKED
MAXLENGTH=n
NAME=name
SRC=url
VALUE=value
SIZE=size>
TYPE This attribute determines which, out of possible choices, type of input
element is being defined. The choices are:
hidden
checkbox
radio
text
password
submit
reset
file
image
ALIGN
Acts similar to ALIGN of the of IMG tag. It determines how the INPUT
element lines up with neighboring elements on the same line within the HTML document.
CHECKED
When the TYPE of the INPUT element is checkbox
or radio button, this attribute can be use to indicate that they are
checked off when the form is initially loaded.
MAXLENGTH
specifies the maximum number of characters allowable in text,
password, and file input elements.
NAME
It specifies the name of the input element benig defined. It is especially usefull for groups
of radio buttons, of which only one item within the same form may be checked at a time.
SRC
When the INPUT elements are of the type IMAGE, SRC can provide the URL to the image
location to be used as a background image. (In fact, this is another way to submit
form by clicking on the image defined through method.)
VALUE
It specifies the default value of the element being defined. For
SUBMIT and RESET buttons, setting the value to a text string
will display that string on the button instead of the words "submit" or
"reset".
SIZE
This attribute determines how wide input fields are rendered in the browser
window.
There are additional attributes of the INPUT tag but they are beyond the scope of this course.
Now let us look at some examples made with the INPUT tag.
SELECT
The SELECT tag defines a selection list on an HTML form. A selection list displays a list of
options from which the user can select an item. If the MULTIPLE attribute is supplied, users
can select multiple options from the list at a time. If the MULTIPLE attribute is not
supplied users can select only one option in the list at a time.
The SIZE attribute specifies how many options in the list are displayed at one time.
For multiple-selection lists, if you do not specify the SIZE attribute, the browser
displays some, maybe all, of the options. For single-selection lists, by default Navigator
displays the list as a drop-down menu that initially shows only one option. The user can
click the list to display the rest of the options. If you specify the SIZE attribute,
the list is displayed as a scrolling list that shows the specified number of options,
regardless of whether the list allows single or multiple selection.
The SELECT tag should be used between <FORM> and </FORM> tags. Use
the OPTION tag to define options in the list.
When the form containing the selection list is submitted to the server, a name/value pair is
sent for each selected option in the list. The basic format of SELECT tag is:
<SELECT NAME=" selectName "
MULTIPLE SIZE=" listLength "
>
<OPTION...>
...
<OPTION...>
</SELECT>
MULTIPLE
specifies that multiple items can be selected. If this attribute is omitted, only one item
can be selected from the list. If multiple selection is enabled, the user usually needs to
hold down the Shift key to select additional items.
NAME="selectName"
specifies the name of the select element. This value is the name
portion of the name/value pair sent to the invoked CGI program when the form is submitted.
The name is not displayed on the form.
SIZE="ListLength"
specifies the number of options visible when the form is
displayed. If the list contains more options than specified by size, the list is displayed
with scrollbars.
OPTION
The OPTION tag specifies an option in a selection list. Use the OPTION tag inside a
SELECTION tag. When the form containing the selection list is submitted to the server,
a name/value pair is sent for each selected option in the list. The value portion of
an option is the value of the VALUE attribute, if it has one, otherwise, it is the text
that follows the <OPTION> tag.
Syntax
<OPTION VALUE=" optionValue "
SELECTED > ... </OPTION>
VALUE="OptionValue"
specifies a value that is returned to the server when the
option is selected and the form is submitted. When no VALUE attribute is present,
the value returned is the same as the text following the <OPTION> tag.
SELECTED
specifies that the option is selected by default.
Now let us look at some examples made with the INPUT tag.
TEXTAREA
The TEXTAREA tag defines a multi-line input field on an HTML form. A text area field lets
the user enter words, phrases, or numbers.
You can defines the number of characters per line the text area can accommodate without
scrolling by supplying the COLS attribute. You can specify that the number of lines that
can appear without scrolling by supplying the ROWS attribute.
Scrollbars appear in the text area if the text in the text area element exceeds the
number of specified columns or rows. TEXTAREA has the following format:
<TEXTAREA COLS=" columns "
NAME=" name " ROWS="
rows " WRAP="OFF"|"HARD"|"SOFT" >
textToDisplay
</TEXTAREA>
COLS="columns"
defines the width (number of characters per line) the text area can
accommodate without scrolling.
NAME="name"
specifies the name of the text area element. This value is the name
portion of the name/value pair sent to the invoked CGI program when the form is
submitted. The name is not displayed on the form.
ROWS="rows"
defines the number of lines (number of rows) the text area can
accommodate without scrolling.
WRAP
specifies whether lines longer than the text area's column width wrap to the next line. The
value of WRAP can be one of the following:
- OFF disables word wrap. Text the user types is displayed with the exact line breaks that
the user types. If the user explicitly inserts a line break, however, the break is included
as part of the text area's value. The user has to scroll horizontally to see the ends of
lines that do not fit in the text area element.
- HARD causes word wrap, and the line breaks are included when the form is submitted.
The text wraps inside the text area element, and that the user does not need to scroll
horizontally.
- SOFT causes word wrap, but the line breaks are not included when the form is submitted.
Now let us look at some examples made with the INPUT tag.
It is now time to look at the FORM tag.
FORM
The action invoked when the user clicks a "Submit" button is defined by the ACTION attribute of
the FORM tag. The value of the ACTION attribute is usually a URL that points to a CGI program.
A CGI program runs on a a server, processes arguments sent by the form, and returns data to
the browser. The value of the form's METHOD attribute also affects the way the CGI program is
invoked. Forms can also send their contents to a mailto: URL as well,
or even have their contents handled by browser-specific scripting languages such as JavaScript.
It is beyond the scope of this tutorial to provide details of CGI programming, but hundreds of
books and tutorials on the Web are available on the subject. We will look some applications
of Javascripts using forms later in this course.
It is important to remember that a document can have multiple forms, but forms cannot
be nested -- you cannot have a form within a form. The basic FORM tag has the following format:
<FORM
ACTION=url
METHOD=get|post>
...
...
</FORM>
ACTION
specifies where FORM data should be sent once the user is done entering the information.
METHOD
defines which of two communications methods will be used to submit the data from the form to
the resource listed in the ACTION attribute; these two methods are
GET andPOST. Information passed from a
form to an ACTION using theGET method will
pass their data along as part of the URL, while data passed according to the
POST method will be placed on the standard input (STDIN),
for whatever resource is listed in the ACTION attribute to read in.
|