Chap 02b - HTML Form
Chap 02b - HTML Form
HTML Form
Prepared for:
CSC264 – Introduction to Web and
Mobile Application
OVERVIEW OF THIS CHAPTER
HOW?
HTML Form:
To create a form within a HTML document, a form element is
used:
<form attributes>
form elements Provide controls on how
</form> data can be collected
E.g: text input,checkboxes, radio
buttons
action Used to specify the address where you want to pass the
data
method Will define how the data will
be sent (either by POST or
GET)
HTML FORM
HTML Form:
For
example:
<form name=“testForm” action=“order.php” method=“get”>
<!--form elements-->
</form>
<form>
<input type =“...”name =“...”>
</form>
HTML FORM: CONTROLS
<form>
<input type =“...”name =“...”> What do you think
this attribute is
</form>
for?
Value Description
reset Defines a reset button (resets all form values to default values)
date Defines a date control (year, month and day (no time))
HTML FORM: CONTROLS
<form>
<input type =“...”name
=“...”>
</form>
Value Description
file Defines a file-select field and a "Browse..." button (for file uploads)
range Defines a control for entering a number whose exact value is not important (like a slider control). Default
range is from 0 to 100
datetime-local Defines a date and time control (year, month, day, hour, minute, second, and fraction of a second
(no time zone)
Other
attributes
HTML FORM: CONTROLS
Text Input Control (Single Line):
HTML FORM: CONTROLS
Attribute Purpose
type Indicates the type of input control will be set to
text
name Will give a name to the
control: Allow server to
recognize the data
value This can be used to provide an initial value inside
the control
size Will specify the width of the text-input control in
terms of
characters
maxlength Will specify the maximum number of
characters a user can enter into the text box
Uses an
element
called
textarea
HTML FORM: CONTROLS
Buttons (Submit):
Buttons (Reset):
HTML FORM: CONTROLS
Buttons (Push Button):
Push buttons have no default behaviour:
It is set to perform some operation when pressed
(could use client-side scripting to trigger an event
when clicked)
HTML FORM: CONTROLS
Grouping Form Data:
The elements within the form can be grouped accordingly by using the
fieldset element
To give a caption for a group of elements, you can use the legend element
HTML FORM: CONTROLS
Radio Button Control:
Usually radio buttons are
used when you want the
user to select only one
option of data out of
many options given
There are other attributes that you can use for the
option tag:
Attribute Purpose
selected Specifies that this option should be the initially selected
value when the page loads
HTML FORM: CONTROLS
Presented as
a
scrolling
list
HTML FORM: CONTROLS
Allow users
to choose
multiple
options
HTML FORM: CONTROLS
Data will be
initially
selected
HTML FORM: LABELS
Label Element:
Is used to create a caption for a form control
Allows user to click on the label, and it will be treated like clicking on
the
associated input element
Uses id
an to
label inp
the ut