Chapter3 Tables&Forms
Chapter3 Tables&Forms
1
Chapter 3
2
Content
Tables
Forms
New HTML5 Form Input Types
Page-Structure/Semantic Elements
Media Elements
3
Tables
Table places information inside the cells
formed by dividing a rectangle into rows and
columns
Most cells contain data; some cells, usually on
the table's top or side, contain headings.
Tags:
A table is specified as the content of a <table> tag
The row headings are specified as the content of a
<th> tag
Each row of a table is specified as the content of a
<tr> tag
Each data cell of a row is specified as the content of a
<td> tag
<caption>….</caption>[optional]
allows to give heading to a table.
Appears with in <table>…</table>
4 Attributes: Align={top, bottom}
Format
<table>
<caption>table caption</caption>
<tr>
<td>…</td> <td>…</td> …
</tr>
<tr>
<td>…</td> <td>…</td> …
</tr>
…
</table>
5
Table Basic Formatting
A border attribute in the <table> tag
specifies a border between the cells
If border is set to "border", the browser’s
default width border is used
The border attribute can be set to a number,
which will be the border width
E.g. border = “4”
Without the border attribute, the table will
have no lines!
border attribute not supported in HTML5, use CSS
6
Table Example
Empty cell
Column
headings
Row
headings
8
Table Attributes
align=“alignment” {left, center, right}
bgcolor=“color”
width=“table width” {absolute or relative}
border=“border width”
bordercolor=“color”
cellspacing=“space amount” {in pixels}
it controls the spacing between adjacent cells
cellpadding=“padding amount” {in pixels}
It controls the distance between data in a cell
and the boundaries of the cell
9
Table Attributes(cont’d)
Table row attributes:
align=“alignment” {left, center, right}
valign=“alignment” {top, middle, bottom}
bgcolor=“color”
height=“height”
Table data/heading attributes:
align=“alignment”
valign=“alignment”
width=“width”
bgcolor=“color”
Unless otherwise specified, <tr> and <td>
inherit attributes of <table> whenever it
applies.
10
Example
<table align=center border=5 cellpadding=10 cellspacing=5
width=250>
<caption >table 1.0</caption>
<tr align=center>
<th>Column 1</th> <th>Column 2</th>
</tr>
<tr>
<td bgcolor=blue>Cell 1</td> <td
bgcolor=gray>Cell2</td>
</tr >
<tr align=center valign=center bgcolor=#FF0055
height=30>
<td>Cell 3</td> <td>Cell 4</td>
</tr>
</table>
11
rowspan and colspan
attributes
colspan=“num columns”
set in the <th> or <td>
one row needs to be a certain number of
columns wide
rowspan=“num rows”
set in the <th> or <td>
Allows a cell to take off more than one row
12
Example
13
Another Example: multiple-labeled
columns and labeled rows
14
Table Sections
Tables naturally occur in two and sometimes
three parts
Header – <thead>
First section, contains header information such
as column names
Groups the header content in a table
Body – <tbody>
Groups the body content in a table
Table’s primary data
Footer – <tfoot>
Groups the footer content in a table
E.g. for calculation results and footnotes
15
Example:
header
body
footer
16
Display: A table with the three sections
17
Exercise: Create the
following table
18
Forms
A form is the usual way information is
communicated from a browser to a server
Used to gather input from users
Modeled from paper form
19
Paper form XHMTL form
Forms
HTML has tags for information gathering
They are called controls or widgets
Example:
Single-line & multiple-line text collection
Checkboxes
All such controls are
Radio buttons
used to gather
Menus information from the
user
The values of all of the controls together in a form
are called the form data
When the Submit button of a form is clicked, the
form’s values are sent to the server
20
The <form> Tag
All of the components (widgets) of a form are
defined in the content of a <form> tag
The only required attribute of <form> is action
specifies the URL of the application that is to be
called when the Submit button is clicked
action =
"http://www.cs.nott.ac.uk/cgi-bin/survey.pl"
if the form has no action, the value is set to the
empty string (“ ”), we will use this for the time being
21
GET
22
When to use POST
23
The <input> Tag
25
The <input> Tag
Password
<input type="password"> defines a
password field
Only bullets or asterisks displayed by
browser
28
The <input> Tag
Radio Buttons
Collections of checkboxes in which only one
button can be ‘checked’ at a time
Every time a radio button is pressed, the button
in the group that was previously on is turned off
29
Example
30
The <select> Tag
[Using checkboxes & radio buttons when the number of choices is large,
the form becomes too long to display.]
Specified with a <select> tag rather than with the
<input> tag
Two kinds:
those that behave like checkboxes and
those that behave like radio buttons , i.e. only one item
can be selected at a time (the default)
That behave like checkboxes are specified by including
the multiple attribute, which must be set to
"multiple"
The name attribute of <select> is required, the
value sent in the form data is the value of this
31
attribute
The <select> Tag
32
Example:
Examples\menu1.html
Examples\menu2.html
34
The <textarea> Tag
Creates a multiline text area
Usually include the rows and cols
attributes to specify the size of the text
area
the default text in a <textarea> tag preserves
all the spaces, returns, and other special
characters.
35
Example
36
Examples\textarea.html
Action Buttons:Submit & Reset
Both are created with <input>
<input type = "reset" value = "Reset Form">
<input type = "submit” value = "Submit Form">
Reset clears all controls to their initial states
Submit has two actions:
1. Encode the data of the form & send to the server
2. Request that the server execute the server-
resident program specified as the value of the
action attribute of <form>
The purpose of such a server-resident program is to process
the form data and return some response to the user
A Submit button is required in every form
37
Example
38
autocomplete Attribute
41
Self-validation:
•New HTML 5 input types are self validating on the client side
•Avoid JavaScript code needed to validate user input
•Reduce the amount of invalid data submitted and consequently
reducing Internet traffic
42
Input Type Color
43
Input Type Date
44
Input Type Datetime-local
45
Input Type Month
46
Input Type Week
48
Input Type Number
The <input type="number"> defines
a numeric input field.
You can also set restrictions on what numbers are
accepted. The following example displays a numeric
input field, where you can enter a value from 1 to 5:
49
HTML5 <datalist> Element
The <datalist> element specifies a list of pre-defined
options for an <input> element.
Users will see a drop-down list of the pre-defined options
as they input data.
The list attribute of the <input> element, must refer to
the id attribute of the <datalist> element.
Note: The datalist tag is not supported in Safari or IE9 (and earlier).
50
Input Type Range
The <input type="range"> defines a control for
entering a number whose exact value is not important
(like a slider control).
Default range is 0 to 100. However, you can set
restrictions on what numbers are accepted with the
min, max, and step attributes:
51
Input Type Search
52
Input Type Tel
53
Input Type Time
54
Input Type Url
The <input type="url"> is used for input fields that
should contain a URL address.
Depending on browser support, the url field can be
automatically validated when submitted.
Some smartphones recognize the url type, and adds
".com" to the keyboard to match url input.
55
Presentation
Tables can be used to align form fields and
their labels so that the presentation of the
form looks more regular.
one possibility is to use:
one table row per input field
within a table row
one column for the labels
one column for the input fields
57
Example of a Complete
Form
58
59
Complete form: Display
60 Examples\popcorn.html
Presentation: Example
<body bgcolor="FF9999" link="white" alink="Blue" vlink="Red">
61
Example(cont’d)
<table width="80%" align="center" cellpadding="20" bgcolor="white">
<tr>
<td bgcolor="white">
<h2>Page Heading</h2>
<hr width="80%" align="left" />
<p>Content goes here. Content goes here. Content goes
here. Content goes here. Content goes here. Content goes here. Content
goes here. Content goes here.
Content goes here.</p>
...more content...
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br
/><br /><br /><br /><br /><br />
<hr />
<center>©-XYZ Company</center>
</td>
</tr>
</table>
</body>
62
Example: output
63
New Semantic Elements in HTML5
64
Why semantic Elements?
•Easy for search engines to identify the correct web page content
65
66
HTML5 <section> Element
The <section> element defines a section in a
document.
According to W3C's HTML5 documentation:
"A section is a thematic grouping of content, typically
with a heading."
67
68
HTML5 <article> Element
69
70
HTML5 <header> Element
71
72
HTML5 <footer> Element
The <footer> element specifies a footer for a document
or section.
A <footer> element should contain information about
its containing element.
A footer typically contains the author of the document,
copyright information, links to terms of use, contact
information, etc.
You may have several <footer> elements in one
document.
73
HTML5 <footer> Element
74
HTML5 <nav> Element
The <nav> element defines a set of navigation links.
NOT all links of a document should be inside a <nav>
element. The <nav> element is intended only for major
block of navigation links.
75
HTML5 <aside> Element
The <aside> element defines some content aside
from the content it is placed in (like a sidebar).
The aside content should be related to the
surrounding content.
76
HTML5 <figure> and <figcaption>
Elements
The purpose of a figure caption is to add a visual
explanation to an image.
In HTML5, an image and a caption can be grouped
together in a <figure> element:
77
HTM5 Media and Graphics
Elements
www.w3schools.com
78
HTM5 Graphics Elements
HTML5 Canvas
The HTML <canvas> element is used to draw graphics on a
web page, via JavaScript.
The <canvas> element is only a container for graphics.
You must use JavaScript to actually draw the graphics.
Draw a Line
80
HTML5 SVG
SVG stands for Scalable Vector Graphics
SVG is used to define graphics for the Web
SVG is a W3C recommendation
The HTML <svg> element is a container for SVG
graphics.
SVG has several methods for drawing paths, boxes,
circles, text, and graphic images.
81
SVG Example: Draw Circle
Other Shapes
82
SVG vs Canvas
83
HTML Google Maps
84
85
86
HTML Multimedia:
Sound, Music, Videos, Movies, Animations – with different types and
formats
Common Video Formats: Only MP4, WebM, and Ogg video are supported
by the HTML5 standard!
87
Audio Formats
Only MP3, WAV, and Ogg audio are supported by the HTML5 standard!
88
HTML5 Video
Before HTML5, a video could only be played in a browser with
a plug-in (like flash).
The HTML5 <video> element specifies a standard way to
embed a video in a web page.
• The controls attribute adds video controls, like play, pause, and volume.
• Include width and height attributes.
• The <source> element allows you to specify alternative video files which the
browser may choose from.
89
HTML5 Audio
Before HTML5, audio files could only be played in a browser
with a plug-in (like flash).
The HTML5 <audio> element specifies a standard way to
embed audio in a web page.
To play an audio file in HTML, use the <audio> element:
90