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.
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.
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
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.
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.
<FORM NAME="LoginForm" METHOD=POST ACTION="urltoInvoke"> <P>User name: <INPUT TYPE="text" NAME="userName" SIZE="10"> <P>Password: <INPUT TYPE="password" NAME="password" SIZE="12"> <P><INPUT TYPE="submit" VALUE="Log in"> <INPUT TYPE="button" VALUE="Cancel" onClick="window.close()"> </FORM>The file forms.htm shows this example in action in a separate window.
NAME="buttonName"
specifies the name of the button. The name does not appear in the form.
VALUE="buttonText"
specifies the text to be displayed in the button.
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.
<FORM METHOD=POST ACTION="/cgi-bin/example.cgi"> <INPUT TYPE="button" VALUE="Close Window" onClick="window.close();"> </FORM>The file forms.htm shows this example in action in a separate window.
<INPUT TYPE="CHECKBOX"
CHECKED
NAME="name"
ONCLICK="JScode"
VALUE="checkboxValue"
>
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.
<P>Specify your music preferences (check all that apply):</P> <BR><INPUT TYPE="checkbox" NAME="musicpref_rnb" CHECKED> R&B <BR><INPUT TYPE="checkbox" NAME="musicpref_jazz" CHECKED> Jazz <BR><INPUT TYPE="checkbox" NAME="musicpref_blues" CHECKED> Blues <BR><INPUT TYPE="checkbox" NAME="musicpref_newage" CHECKED> New AgeThe file forms.htm shows this example in action in a separate window.
If a a form contains a file input element, the value of the ENCTYPE attribute of the FORM tag should be "multipart/form-data".
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.
<FORM ENCTYPE="multipart/form-data" ACTION="/cgi-bin/example.cgi" METHOD="POST"> <P>File name: <INPUT TYPE="file"> </FORM>The file forms.htm shows this example in action in a separate window.
This tag provides a mechanism for delivering a value to the CGI program without the user having entered it, but note that it is not very hidden because the user can discover it by viewing the document source.
NAME="name"
specifies the name of the input 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.
VALUE="value"
specifies the initial value of the input element.
<FORM NAME="LoginForm" METHOD=POST ACTION="/cgi-bin/example.cgi"> <P>Password: <INPUT TYPE="password" NAME="password" SIZE="12" VALUE="treasure"> <INPUT TYPE="hidden" NAME="DefaultPass" VALUE="treasure"> </FORM>The file forms.htm shows this example in action in a separate window.
ALIGN
specifies the alignment of the image in relation to the surrounding text. If you do not specify a value for ALIGN, Navigator uses BOTTOM as the default. The possible values are LEFT, RIGHT, TOP, ABSMIDDLE, ABSBOTTOM, TEXTTOP, MIDDLE, BASELINE, and BOTTOM. See the section "IMG" for a description of the values. Navigator 1.1
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.When Navigator sends the offsets of the image to the server, it sends them as name.x and name.y.
SRC="location"
specifies the URL of the image to be displayed in the document.
<CENTER><INPUT TYPE="image" SRC="signnow.gif"></CENTER>The file forms.htm shows this example in action in a separate window.
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.
<P>Password: <INPUT TYPE="password" NAME="password" VALUE="" SIZE="25">The file forms.htm shows this example in action in a separate window.
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.
<P>Category: <BR><INPUT TYPE="radio" NAME="category" VALUE="liv" CHECKED> Living <BR><INPUT TYPE="radio" NAME="category" VALUE="din"> Dining <BR><INPUT TYPE="radio" NAME="category" VALUE="bed"> BedroomThe file forms.htm shows this example in action in a separate window.
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.
<FORM> <P>State: <INPUT TYPE="text" NAME="state" VALUE="CA" SIZE="2"> <P><INPUT TYPE="reset" VALUE="Clear Form"> </FORM>The file forms.htm shows this example in action in a separate window.
NAME="name"
specifies the name of the input element. The name is not displayed on the form.
VALUE="label"
specifies the text to display on the face of the submit button.
<INPUT TYPE="submit" NAME="SubmitButton" VALUE="Done">The file forms.htm shows this example in action in a separate window.
MAXLENGTH="maxChars"
specifies the maximum number of characters a text box can accept.
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.
ONBLUR="JScode"
specifies JavaScript code to execute when the text element loses keyboard focus. For information about JavaScript, see the JavaScript Guide or the JavaScript Reference..
ONCHANGE="JScode"
specifies JavaScript code to execute when the text element loses focus and its value has been modified.
ONFOCUS="JScode"
specifies JavaScript code to execute when a user clicks the text element. See the JavaScript Guide forSee the JavaScript Guide for more information.
ONSELECT="JScode"
specifies JavaScript code to execute when a user selects some of the text in the text element.
SIZE="lengthChars"
specifies the length of the input field, in characters.
VALUE="text"
specifies the initial value of the text element.
<P>Last name: <INPUT TYPE="text" NAME="last_name" VALUE="" SIZE="25">The file forms.htm shows this example in action in a separate window.
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.
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.
<FORM> <B>Shipping method:</B><BR> <SELECT> <OPTION> Standard <OPTION SELECTED> 2-day <OPTION> Overnight </SELECT> </FORM>
<FORM> ... <B>Music types for your free CDs:</B><BR> <SELECT NAME="music_type_multi" MULTIPLE> <OPTION> R&B <OPTION> Jazz <OPTION> Blues <OPTION> Reggae </SELECT> . </FORM>
<FORM> <SELECT NAME="fruit_choices" MULTIPLE> <OPTION>Apples <OPTION SELECTED>Bananas <OPTION>Cherries <OPTION>Oranges <OPTION>Pineapple <OPTION>Figs <OPTION>Guava </SELECT> </FORM>The file forms.htm shows this example in action in a separate window.
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.
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:
<FORM> <B>Description:</B> <BR><TEXTAREA NAME="item_description" ROWS="6" COLS="55"> This is the first line. This is the second line. This is the last line. </TEXTAREA> </FORM>
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.
<FORM> <TEXTAREA NAME="item_description" COLS=40 ROWS="4" WRAP="SOFT"> For faster response, include a full description of your problem, and tell us what hardware configuration you are using.
Also include your registration number. </TEXTAREA> </FORM>The file forms.htm shows this example in action in a separate window.
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.
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.
<FORM.....> ... <KEYGEN NAME="somekey" CHALLENGE="1125983021"> ... </FORM>
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.
PROMPT="text"
specifies the text that appears as the search prompt in the browser. Navigator 1.1.
cat << EOF <HEAD> <ISINDEX PROMPT="Enter a search keyword:"> </HEAD> EOF
Last Updated: 01/26/98 21:33:44
Copyright © 1998 Netscape Communications Corporation