Chapter03 HTML Forms
Chapter03 HTML Forms
Forms
• The FORM element is used to create a data input form.
• A Form is an area that can contain Form
Control/Elements.
• A region using forms is enclosed within the <FORM>
</FORM> tags.
• A form usually contains a Submit button to send the
information in the form elements to the server
• The FORM element has two important attributes:
– ACTION
– METHOD.
Form Processing
HTML
Form
B Data from
Input
r Form
Data from Form
o Web
User Form Processing
w Server Program
s HTML
(CGI)
Output e Document Data
Flow
r HTML
Document
Database
Management
System
</Form>
Forms
• Form Input: INPUT
– Only used within a FORM element and is denoted by
<INPUT>.
– Attributes:
• TYPE: Defines the type of data used in the field.
• VALUE: Contain the initial value displayed to users.
• NAME: The name of the particular element.
• MAXLENGTH: The maximum number of characters that can be
entered by users in a text field.
• SIZE: Specifies the size of the field and depends on its type.
• SRC: Denote URL for an image.
• CHECKED: Indicates that a checkbox or radio button is selected.
• DISABLED: Prevents the field from receiving focus.
• ALIGN: Alignment if image is used.
• READONLY: Prevents modification of the contents of the field.
TYPE Attribute
• TEXT type:
– Specifies a single line text entry field.
– The default width is 20 characters,
– MAXLENGTH and SIZE attributes is used to limit the number
of characters (MAXLENGTH <= SIZE)
• Example : A text field named "text2" that is 30 characters wide but will
only accept 20 characters.
• <input type="text" name="text2" size="30" maxlength="20">
• Example : A password field named "pass2" that is 30 characters wide but will
only accept 20 characters
• <input type="password" name="pass2" size="30" maxlength="20">
Text Input (type=“textarea”)
• Text fields that have more than one line and can scroll as the viewer enters
more text.
• The tag options define the size of the field by the number of rows and character
columns.
• You can also include default text to appear in the field
11
TYPE Attribute
• SUBMIT and RESET Types:
– SUBMIT: Used to submit the form’s content, as
specified by the ACTION attribute.
– RESET: Set all fields in the form to their initial
values.
<P>INPUT TYPE=SUBMIT>
<INPUT TYPE=RESET>
• If you click one radio button, the others in the set are automatically de-
selected.
• A set of radio buttons is defined by providing them the same name
<FORM><P><INPUT TYPE=“button”
VALUE=“Back to Last Document”
onClick=“history.back( )”></P></FORM>
PullDown Menu
• Use SELECT and OPTION to create pulldown menu.
• SELECT:
– Allows the user to choose one (or possibly more) items from a
list.
– Attributes: MULTIPLE, SIZE, and NAME.
• OPTION:
– Specifies the list items.
– Attributes: SELECTED, VALUE, and LABEL
• A menu or list:
<select name="select">
<option value="red">red</option>
<option value="green">green</option>
<option value=“blue">blue</option>
</select>
Practice Exercise
18