HTML Tutorial.06
HTML Tutorial.06
1
XP
Objectives
3
The Interaction between a XP
Web Page Form and a CGI Script
4
XP
Working with CGI Scripts
5
XP
CGI Scripts
CGI scripts made possible many things like;
online database containing customer information
catalogues for ordering and purchasing items online
databases containing product support information
determining the number of times a Web page has
been accessed
server-side image maps
message boards for online discussion forums
e-mail for discussion groups
6
XP
CGI Script Restrictions
There are several reasons to restrict direct
access to CGI scripts:
CGI scripts are actually running a program
directly on the server
security risks from computer hackers
drain on system resources caused by large
numbers of programs running simultaneously
System administration are understandably
careful to maintain strict control over their
servers and systems.
7
CGI Scripts and Computer XP
Languages
CGI scripts can be written in a variety of different
computer languages. Some of the most commonly used
languages are:
AppleScript
ASP
C/C++
Perl
TCL
The UNIX shell
Visual Basic
The computer language used depends on the Web
server.
8
Form Components and XP
Elements
text box
First Name Last Name
This figure shows Address #1
form Send
SendRegistration
Registration Cancel
Cancel
button
9
XP
Form Control Elements
11
XP
The <form> Tag
14
XP
Structuring a Form
Horizontal lines can provide structure
to a form by separating sections.
15
XP
contact information
product information
usage information
comments
buttons
16
XP
Input Types
This figure Type Description
shows other type=”button” Display a button which can be clicked to
perform an action from a script
supported
type=”checkbox” Display a check box
HTML input
types. type=”file” Display a browse button to locate and select a
file
type=”hidden” Create a hidden field, not viewable on the form
type=”image” Display an inline image which can be clicked to
perform an action from a script
type=”password” Display a text box in which hides text entered
by the user
type=”radio” Display a radio (option) button
type=”reset” Display a button which resets the form when
clicked
type=”submit” Display a button which submits the form when
clicked
type=”text” Display a text box in which displays text
entered by the user
17
XP
Working with Text Boxes
box
size attribute defines the width of the text box in
number of characters
maxlength attribute defines the maximum number
21
XP
CGI Script Names
23
Controlling the Size of a XP
Text Box
characters
24
Setting the Width of XP
Text Boxes
This figure
shows an
example of code
for setting the
width of text
boxes.
25
Result of Setting the XP
Netscape users
may have to
close and open
the file for the
changes to the
Web form to
take effect.
26
Setting the Maximum LengthXP
for Text Input
Setting the width of a text box does not limit the
number of characters the box can hold.
if a user enters text longer than the box’s width, the
text scrolls to the left
the user cannot see the entire text, but all of it is
sent to the CGI script for processing
The syntax for setting the maximum length for field
input is:
<input maxlength=“value”>
value is the maximum number of characters that
can be stored in the field
27
Specify the Maximum Length XP
for a Field
This figure shows an example of limiting the width of the zip code field to five characters.
no more than 5
characters are
allowed in this text
box
28
Setting a Default Value for aXP
Field
When the same value is entered into a field,
it may make sense to define a default value
for a field.
Default values can save time and increase
accuracy for users of a Web site.
To define a default value, use the following
syntax:
<input value=“value”>
value is the default text or number that is
displayed in the field
29
Defining a Default Value for a XP
Field
If customers from countries other than the United States use this Web form,
they can remove the default value by selecting the text and pressing the Delete key.
default value
30
XP
Creating a Password Field
form
label text is the text of the label
32
Creating a Label for the XP
fname Field
This figure shows
a label for the
fname field.
value of the id
attribute for the first
name field
33
XP
Creating a Selection List
34
Using the <select> XP
36
XP
Using a Selection List
Your selection
list might look
slightly different
depending on the
browser and
browser version.
37
Modifying the Appearance XP
of a Selection List
HTML provides several attributes to modify the
appearance and behavior of selection lists and
options.
By default, the <select> tag displays one option
from the selection list, along with a list arrow to view
additional selection options.
The number of options displayed can be modified
with the size attribute.
The syntax of the size attribute is:
<select size=“value”>
38
Modifying the Appearance XP
39
Selection Lists with XP
Different Size Values
This figure shows
selection lists with
different size
values. size = "1" size = "4"
41
Making Multiple Selections XP
Continued
The Windows operating system, multiple
selections can be made as follows:
for noncontiguous selections, press and hold
the Ctrl key while you make your selections
for a contiguous selection, select the first
item, press and hold the Shift key, and then
select the last item in the range
Check and verify that the CGI scripts used are
designed to handle multiple selection lists.
42
XP
Working with Option Values
44
XP
Option Groups
option
a single group label
option
group a single option
group
45
XP
Working with Radio Buttons
Radio buttons display a list of choices from which a
user makes a selection.
Only one radio button can be selected at a time.
The syntax to create a radio button is:
<input type=“radio” name=“name” id=“id”
value=“value”>
name identifies the field containing the radio button
id attribute identifies the specific option. Only required
if you intend to use a field label with the radio button
value attribute indicates the value sent to the CGI
script, if that radio button is selected by the user
46
XP
Creating Radio Buttons
This figure shows an example of HTML code that creates radio buttons for party affiliations.
In this sample code, the value sent to the CGI script does not match the field label.
If the user selects the Republican radio button, the value “gop”
is sent to the CGI script paired with the field name “party.”
47
Selection Lists vs. Radio XP
Buttons
49
Creating a Group Box XP
Continued
50
Creating a Group Box and XP
Legend
start of group box
This figure shows group box legend
an example of a
group box applied
to a set of radio
buttons.
51
XP
Group Box Size
There is no attribute to control the size of a group
box.
The box’s height will be large enough to
accommodate the fields and labels in the field set.
The width is the width of whatever space remains
on the Web page.
To set the width to a specific value use a table cell
to place the group box and set the width of the cell.
group boxes cannot extend across table cells; all of
the fields in the field set must be placed within a
single cell
52
XP
Working with Check Boxes
53
XP
54
Group Boxes for Radio Buttons XP
and Check Boxes
55
XP
Creating a Text Area
57
XP
Wrap Attribute Values
The text entered in a text area wraps to the next line when it exceeds the width of the
box. To control how a browser wraps text to a new line use the wrap attribute.
This figure shows the three possible wrap options.
58
XP
The wrap Attribute for Text
60
XP
Creating Form Buttons
61
XP
Creating a Push Button
One type of button, called a push button, is
created using the <input> tag as follows:
<input type=“button” value=“text”>
text is the text that appears on the button
62
Creating Submit and Reset XP
Buttons
A submit button is a button that submits
the form to the CGI script for processing.
A reset button resets the form to its original
(default) values.
The syntax for creating these two buttons is:
<input type=“submit” value=“text”>
<input type=“reset” value=“text”>
value attribute defines the text that appears on
the button
63
The name and value XP
Attributes
The name and value attributes can be used
for push, submit, and reset buttons.
Use these attributes when the form contains
multiple buttons and a program that
processes the form needs to distinguish one
button from another.
for example, a Web page advertising a shareware
program might include three buttons:
one used to download the program
another used to retrieve information
the third to cancel the form
64
XP
Creating a Form Button
The figure shows HTML tags for buttons that download a program,
retrieves information, and resets the form to its original values.
65
Creating Buttons XP
with the <button> Tag
Buttons created with the <input> tag do not allow the Web
page designer to control the appearance of the button.
For greater artistic control over the appearance of the
button, use the <button> tag.
The syntax of the <button> tag is:
<button name=“name” value=“value”
type=“option”>
button text and HTML tags
</button>
name attribute specifies the name of the button
value attribute sends to a CGI script
type attribute specifies the button type (submit, reset, or
button)
66
XP
Using the <button> Tag
67
XP
Creating File Buttons
68
XP
Using a File Button
Inline images can act like submit buttons, so that when the user
clicks the image, the form is submitted.
The syntax for this type of control element is:
<input type=“image” src=“URL” name=“text”
value=“text”>
URL is the filename and location of the inline image
name attribute assigns a name to the field
value attribute assigns a value to the image
When the form is submitted to the CGI script, the coordinates of
where the user clicked are attached to the image’s name and value
in the format: namex_coordinate, value.y_coordinate.
70
Using an Image Control XP
with a CGI Script
71
XP
Working with Hidden Fields
A hidden field is added to the form but not
displayed in the Web page.
Because the field is hidden, it can be placed
anywhere between the opening and closing
<form> tags.
The syntax for creating a hidden field is:
<input type=“hidden” name=“name”
value=“value>
Place all hidden fields in one location to make it
easier to read and interpret the HTML code.
Include a comment describing the purpose of the
field.
72
XP
73
XP
Working with Form Attributes
77
Form Values XP
78
XP
Using the “mailto” Action
80
Mail Message Created UsingXP
the “mailto” Action
This figure
shows an e-mail
message that
the “mailto”
action
generated for a
registration
form.
The format of
the mail
message may
look different
depending on
the browser or
e-mail software.
81
XP
Summary
82
XP
Summary Continued