This section discusses the tags for creating forms.
* FORM
* INPUT
o INPUT TYPE="BUTTON"
o INPUT TYPE="CHECKBOX"
o INPUT TYPE="FILE"
o INPUT TYPE="HIDDEN"
o INPUT TYPE="IMAGE"
o INPUT TYPE="PASSWORD"
o INPUT TYPE="RADIO"
o INPUT TYPE="RESET"
o INPUT TYPE="SUBMIT"
o INPUT TYPE="TEXT"
* SELECT
* OPTION
* TEXTAREA
* KEYGEN
* ISINDEX
FORM
(form for user input)
The FORM tag creates an HTML 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, such as or
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.
Kinds of Interface Elements
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.
Submit Buttons and CGI Programs
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 or an tag.
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. It is beyond the scope of this reference to provide details of CGI programming, but many fine books are available on the subject, and also lots of information is available on the web. A good starting point is:
http://hoohoo.ncsa.uiuc.edu:80/cgi/overview.html
ONCLICK and ONSUBMIT
You can also define OnClick event handlers for several kinds of input elements. An OnClick event handler is a piece of JavaScript code that is executed when the element is clicked. For information about JavaScript, see the JavaScript Guide or the JavaScript Reference.
The FORM tag has an optional ONSUBMIT attribute, whose value is a JavaScript event handler that executes when a "Submit" button in the form is pressed. If the JavaScript code returns false, the form's action ends there, and the URL specified by the ACTION attribute is not invoked. If the JavaScript code returns anything else, the URL specified by the ACTION attribute is invoked. For example, you could use the ONSUBMIT attribute to check whether or not the user really wants to submit the form.
Name/Value Pairs
When a form is submitted, the data contained in the form is sent to the invoked CGI program as a series of name/value pairs. The name portion of each pair is the name of an interface element as specified by its NAME attribute. In most cases the value portion is the value displayed by the element, for example, the text displayed in a text field.
Nesting Forms
A document can have multiple forms, but forms cannot be nested -- you cannot have a form within a form. If your document uses positioned HTML content, each form must be completely contained within one positioned block. For more information on positioning HTML content, see Part 2, Positioning HTML Content in Dynamic HTML in Netscape Communicator.
Syntax
The ACTION attribute is required if any action is to occur when the user presses a "Submit" button in the form.
ACTION="serverURL"
specifies the URL of the program to be invoked when the form is submitted. The action can also be a mailto: URL if the form results are to be mailed to someone.
ENCTYPE="encodingType"
specifies the MIME encoding of the data sent:
* "application/x-www-form-urlencoded" (the default), is usually used if the METHOD attribute has the value POST.
* "multipart/form-data" is used when the form contains a file upload element (INPUT TYPE="FILE").
METHOD
specifies how information is sent to program invoked by submitting the form.
* GET (the default) appends the input information to the URL which on most receiving systems becomes the value of the environment variable QUERY_STRING.
* POST sends the input information in a data body that is available on stdin with the data length set in the environment variable CONTENT_LENGTH.
NAME="formName"
specifies the name of the form. The name is not displayed on the form. JavaScript can use the NAME attribute to differentiate different forms if there are multiple forms on a page. For information about JavaScript, see the JavaScript Guide or the JavaScript Reference.
ONRESET="JScode"
specifies JavaScript code that executes when a user resets the form by using a RESET button.
ONSUBMIT="JScode"
specifies JavaScript code that executes when a user submits the form by clicking a "Submit" button.You can use the ONSUBMIT attribute to prevent a form from being submitted; to do so, put a return statement that returns false in the JavaScript code. Any other returned value lets the form submit. If you omit the return statement, the form is submitted.
TARGET="windowName"
specifies the window that displays the data returned by the invoked program. See the description of special target values in the "A as link" section for a list of the pre-defined target values. Navigator 2.
Example
The following example creates a form called LoginForm that contains text fields for user name and password, a submit button, and a cancel button.
The file forms.html shows this example in action in a separate window.
INPUT TYPE="CHECKBOX"
A checkbox is a toggle that the user can select (switch on) or deselect (switch off.)
Syntax
CHECKED
indicates that the checkbox is displayed with a tick mark to indicate that it is selected.
NAME="name"
specifies the name of the input element. This value is the name portion of the name/value pair for this element that is sent to the server when the form is submitted. The name is not displayed on the form.
ONCLICK="JScode"
specifies JavaScript code to execute when a user clicks the checkbox. For information about JavaScript, see the JavaScript Guide or the JavaScript Reference.
VALUE="checkboxValue"
specifies the value to be returned to the server if the checkbox is selected when the form is submitted. The default value is ON, but you can specify a different value if you want. When the form is submitted, only the name/value pairs for selected checkboxes are sent to the invoked CGI program.
Example
Specify your music preferences (check all that apply):
R&B
Jazz
Blues
New Age
The file forms.html shows this example in action in a separate window.
INPUT TYPE="FILE"
This places an element on an HTML form that lets the user supply a file as input. When the form is submitted, the content of the specified file is sent to the server as the value portion of the name/value pair for this input element. Netscape Navigator displays a "Browse" button next to the file input element that lets users select a file from their system to use as the value of the file input element. Navigator 2.0
If a a form contains a file input element, the value of the ENCTYPE attribute of the FORM tag should be "multipart/form-data".
Syntax
NAME=name
specifies the name of the input element. This value is used as the name portion of the name/value pair for this element that is sent to the server when the form is submitted. The name is not displayed on the form.
VALUE=filename
specifies the initial value of the input element.
Example
The file forms.html shows this example in action in a separate window.
INPUT TYPE="PASSWORD"
A password element is a text input field in which each character typed is displayed as a character such as * or a black dot to conceal the actual value.
Syntax
MAXLENGTH="maxChar"
specifies the maximum number of characters a password box can accept.
NAME="name"
specifies the name of the input element. This value is used as the name portion of thename/value pair for this element that is sent to the server when the form is submitted. The name is not displayed on the form.
ONSELECT="JScode"
specifies JavaScript code to execute when a user selects some of the text in the text element. For information about JavaScript, see the JavaScript Guide or the JavaScript Reference.
SIZE="charLength"
specifies the length of the input field, in characters. The value should be an integer.
VALUE="textValue"
specifies the initial value of the password, if any.
Example
Password:
The file forms.html shows this example in action in a separate window.
INPUT TYPE="RADIO"
A radio element is a radio button. A set of radio buttons consists of multiple radio buttons that all have the same NAME attribute. Only one radio button in the set can be selected at one time. When the user selects a button in the set, all other buttons in the set are deselected. If one radio button in a set has the CHECKED attribute, that one is selected when the set is first laid out on the window.
Syntax
CHECKED
indicates that the radio button is selected.
NAME="name"
specifies the name of the input element. This value is used as the name portion of the name/value pair for this element that is sent to the invoked CGI program when the form is submitted. The name is not displayed on the form. All radio buttons that have the same name constitute a radio group; only one radio button of a group can be set at one time.
ONCLICK="JScode"
specifies JavaScript code to execute when a user clicks the radio button. For information about JavaScript, see the JavaScript Guide or the JavaScript Reference.
VALUE="value"
specifies the value that is returned to the server when the radio button is selected and the form is submitted. Only name/value pairs for radio buttons that are selected are sent to the invoked CGI program. The value defaults to ON.
Example
The following example creates a radio button group.
Category:
Living
Dining
Bedroom
The file forms.html shows this example in action in a separate window.
INPUT TYPE="RESET"
When a user presses a reset button, all elements in the form are reset to their default values
Syntax
NAME="name"
specifies the name of the input element.
ONCLICK="JScode"
specifies JavaScript code to execute when a user clicks the button. For information about JavaScript, see the JavaScript Guide or the JavaScript Reference.
VALUE="label"
specifies the text to display on the face of the reset button.
Example
This example displays a text element with the default value CA and a reset button labelled Clear Form. If the user types a state abbreviation in the text element and then clicks the Clear Form button, the original value of CA is restored.
Last name:
The file forms.html shows this example in action in a separate window.
SELECT
(selection list in a form)
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 MUTLIPLE 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
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.
Syntax
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.
ONBLUR="blurJScode"
specifies JavaScript code to execute when the select element loses focus. For information about JavaScript, see the JavaScript Guide or the JavaScript Reference..
ONCHANGE="changeJScode"
specifies JavaScript code to execute when the select element loses focus and its value has been modified.
ONCLICK="JScode"
specifies JavaScript code to execute when a user clicks an item in the list.
ONFOCUS="focusJScode"
specifies JavaScript code to execute when the element gets focus.
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.
Used Within
FORM
Select Example 1:Single Item Selection
Example 2: Multiple Selection
Example 3: Multiple Selection With Default
In the following example, all seven options can be chosen, but bananas are selected by default. The list is displayed as a scrollable menu that fits four options at a time.
The file forms.html shows this example in action in a separate window.
OPTION
(option in a SELECT list)
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 tag.
Syntax
...
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 tag.
SELECTED
specifies that the option is selected by default.
Used within
FORM
Example
See Select Example 1:Single Item Selection.
TEXTAREA
(text field on a form)
The TEXTAREA tag defines a multiline 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.
To begin a new line in a text area element, use a new paragraph. For example, the following text area element contains two lines, a blank line, then one line:
Syntax
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.
ONBLUR="JScode"
specifies JavaScript code to execute when the text area element loses focus. For information about JavaScript, see the JavaScript Guide or the JavaScript Reference..
ONCHANGE="JScode"
specifies JavaScript code to execute when the text area element loses focus and its value has been modified..
ONFOCUS="JScode
specifies JavaScript code to execute when a text area element receives focus.
ONSELECT="JScode"
specifies JavaScript code to execute when a user selects some of the text in the text area element.
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. Navigator 2.0.
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.
Used Within
FORM
Example
The following example creates a text area element that is 4 rows long and 40 columns wide. When the form loads, the text area element contains several lines of text, including one blank line.
The file forms.html shows this example in action in a separate window.
KEYGEN
(generate key material)
The KEYGEN tag facilitates the generation of key material and submission of the public key as part of an HTML form. This mechanism is designed for use in web-based certificate management systems. It displays a menu of key-size choices from which the user must choose one. Then, when the submit button is clicked, a key pair of the selected size is generated. The private key is encrypted and stored in the local key database.
The public key and challenge string are DER encoded as PublicKeyAndChallenge and then digitally signed with the private key to produce a SignedPublicKeyAndChallenge. The SignedPublicKeyAndChallenge is base64 encoded, and the ASCII data is finally submitted to the server as the value of a name-value pair, where the name is specified by the NAME attribute of the KEYGEN tag.
Syntax
The NAME attribute is required
NAME="name"
specifies the name for the name/value pair.
CHALLENGE="challenge"
specifies the challenge string to be packaged with the public key in the PublicKeyAndChallenge for use in verification of the form submission. If no challenge string is provided, then it is encoded as an IA5STRING of length zero.
Used Within
FORM
Example
...
...
ISINDEX
(searchable index)
The ISINDEX tag causes the web page to display a text entry field in which the user can type a string. The intent of this tag is that it "switches on searching" in the page, but in reality, this tag is useful only if the page is generated by a CGI program.
The intent is that when the user enters text into the text entry field and presses the Return key (or clicks an appropriate button on the browser), the CGI program is invoked again, with the arguments generated from the data in the text field. The browser outputs a new page whose content is determined by what the user entered in the text field.
The CGI program should test for the presence of arguments. If there are none, it should display a default page that includes the ISINDEX tag in the header. If there are arguments, the script does whatever it needs to do. The string entered by the user is the first argument, and the language your script uses determines how you access the first argument.
It is beyond the scope of this reference to provide details on CGI programming, but many fine books are available on the subject, and lots of information is available on the web. A good starting point is:
http://hoohoo.ncsa.uiuc.edu:80/cgi/overview.html
Note that ISINDEX does not require a closing tag.
Syntax
PROMPT="text"
specifies the text that appears as the search prompt in the browser. Navigator 1.1.
Used Within
HEAD
Example
The following snippet of code from a CGI program generates the header for an HTML page. When the page is displayed, it has a text entry field whose prompt is "Enter a search keyword:".
cat << EOF
EOF
No comments:
Post a Comment