1
JavaScript
HTML Forms
Form Elements
• An HTML form begins with the <FORM> tag.
• This tag indicates that a form is beginning, and it
enables form elements to be used.
• The <FORM> tag includes three parameters:
– NAME is simply a name for the form. The NAME of the
form is to be used with JavaScript.
– METHOD is either GET or POST; these are the two ways
– ACTION is a script or program that the form data will
be sent to when submitted.
Form Elements
<FORM NAME="Order" METHOD="GET" ACTION="order.cgi">
For a form that will be processed entirely by
JavaScript (such as a calculator or interactive
game), the METHOD and ACTION
attributes are not needed. You can use a
simple <FORM> tag that names the form:
<FORM NAME="calculator">
Text Field
• This tag is followed by a TYPE parameter to
determine which type of input is expected.
Text Fields and Text Areas
– The first such field is the TEXT field.
– This enables the user to enter text in a one-line area.
– Example:
<INPUT TYPE="TEXT" NAME="text1" VALUE="textField" SIZE="30">
– This defines a text field called text1. The field is given a
default value of "hello" and allows up to 30 characters to
be entered.
Password Field
• An alternate form of text field is the PASSWORD
field.
• This is a specialized text field that displays the text
as asterisks on the screen.
• This type of input is often used for passwords so
that observers don't see which password is being
entered.
<INPUT TYPE="PASSWORD" NAME="textPassword" SIZE=30>
Text Area
• A third option is the text area, which allows
multiple lines of text to be entered. Rather than
using the <INPUT> tag, text areas are defined with
a special tag, <TEXTAREA>.
• A typical <TEXTAREA> definition:
<TEXTAREA NAME="text1" ROWS="2" COLS="70"> ... </TEXTAREA>
• This is the content of the TEXTAREA tag.
</TEXTAREA> The text between the opening and
closing <TEXTAREA> tags is used as the initial
value for the text area.