HTML 3
HTML 3
30-Nov-22
Parts of a Web Form
■ A Form is an area that can contain Form
Control/Elements.
2
Parts of a Web Form
■ Users enter or select a field using Form
Control/ Elements.
3
Control Elements
■ Input Boxes – for text and numerical entries
■ Option Buttons, also called Radio Buttons – for
selecting a single option from a predefined list
■ Selection Lists – for long lists of options,
usually appearing in a Drop-Down List Box
■ Check Boxes – for specifying yes or no
■ Text Areas – for extended entries that can
include several lines of text
4
HTML Forms
■ The basic construction of a HTML form is this...
<form> - begin a form
<input> - ask for information in one of several
different ways
<input> - there can be as many input areas as you
wish
</form> - end a form HTML form
5
Forms and Server-Based
Programs
■ Forms are used to collect information.
■ The information is then sent back to the server.
■ Information is stored and analyzed using a
program on the server.
■ By giving users access to programs that react
to user input, the Web became a more
dynamic environment where companies and
users could interact.
6
Forms and Server-Based
Programs
■ Server-Based programs provide:
■ Online databases containing customer information
■ Online catalogs for ordering and purchasing
merchandise
■ Dynamic Web sites with content that is constantly
modified and updated
■ Message boards for hosting online discussion
forums
7
Forms and Server-Based
Programs
■ Because these programs run on Web servers, rather
than locally, users might not have permission to create
or edit them. Instead, users will receive information
about how to interact with the programs on the server.
8
Forms and Server-Based
Programs
■ Server-Based Programs
■ Common Gateway Interface (CGI) Scripts
■ Most common
■ ASP
■ Cold Fusion
■ C/C++
■ PHP
■ VBScript
■ The Web server determines which language
your Web form will use.
9
Getting Started
■ The first step in creating a form is to specify the name and
location of the CGI script that will be used to process the form
data. To do this, type the following code within your HTML file,
and note that there are no spaces:
10
Text Input (type=“text”)
■ A Text Field:
■ used to create one line fields that viewers can type text. The
default width is 20 characters, and you can create fields of
other sizes by the value in the size option. You can limit the
number of characters by the value of the MAXLENGTH
option. Text input fields will be empty when the page loads,
unless you provide an initial text string for its VALUE option
11
Text Input (type=“text”)
■ Example 1: A text field named "text1" that is 30 characters
wide.
■ <input type="text" name="text1" size="30">
12
Password Input
(type=“password”)
■ are exactly the same as text input elements, except that when the
viewer types in, they see "bullet" characters rather then the letter
they are typing. Password text is scrambled during transmission
and then unscramble when the form data is received at the
server end.
13
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. By adding
the option WRAP=VIRTUAL, the text entered will automatically
wrap at the right hand side of the field. You can also include
default text to appear in the field
14
Adding Control Buttons
■ A form must include at least one control
button for submitting the information once it
is filled out. In addition, forms often include a
button for resetting all the entries if a person
wants to start over.
15
Adding Control Buttons
■ A submit button:
<input type="submit" name="Submit" value="Submit">
■ A reset button:
<input type="reset" name="Submit2" value="Reset">
16
Radio buttons (type=“radio”)
■ Are sets of controls that are linked so that only one radio button
among each set is selected at a time
■ If you click one radio button, the others in the set are
automatically de-selected
■ The value sent in the web form is the value of the radio button
that was last selected
17
Radio buttons (type=“radio”)
Radio buttons:<br>
<input type="radio" name="radiobutton" value="myValue1">
male<br>
<input type="radio" name="radiobutton" value="myValue2" checked>
female
18
Checkboxes (type=“checkbox”)
■ Are similar to radio buttons, but are not affected by
other buttons, so you can have more than one in a
group checked at a time
■ type: “checkbox”
■ name: used to reference this form element from
JavaScript
■ value: value to be returned when element is
checked
■ Note that there is no text associated with the
checkbox—you have to supply text in the
surrounding HTML
20
Drop-down menu or list
■ A menu or list:
<select name="select">
<option value="red">red</option>
<option value="green">green</option>
<option value=“blue">blue</option>
</select>
■ Additional arguments:
■ size: the number of items visible in the list (default is "1")
■ multiple: if set to "true", any number of items may be
selected (default is "false")
21
Practice Exercise
22
A complete example
<html>
<head>
<title>Get Identity</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body>
<p><b>Who are you?</b></p>
<form method="post" action="">
<p>Name:
<input type="text" name="textfield">
</p>
<p>Gender:
<input type="radio" name="gender" value="m">Male
<input type="radio" name="gender" value="f">Female</p>
</form>
</body>
</html>
23