Java Script
Java Script
1 Web Programming
HTML
• Invented by British physicist Tim Berners-Lee in 1990
• HTML, an acronym for HyperText Markup Language, is a
computer language for creating websites and web
applications.
• Consisting mainly of a series of codes usually written in a
text file and then saved as html
• code written in the HTML language translates into a
beautiful, well-formatted text or a combination of text and
media when viewed through a browser.
2 Web Programming
HTML Versions
• HTML 1.0: This was the barebones version of HTML and
the very first release of the language.
• HTML 2.0: This version was introduced in 1995 and it
gradually evolved to allow extra capabilities including:
form-based file upload, tables, client-side image maps and
internationalization.
• HTML 3.2: In an attempt to ensure development of
standards for the World Wide Web, the World Wide Web
Consortium (W3C) was founded by Tim Berners-Lee in
1994. By 1997, they published HTML 3.2.
3 Web Programming
HTML Versions..
• HTML 4.0: Later in 1997, the W3C released HTML 4.0 — a
version that adopted many browser-specific element types and
attributes.
• HTML 4.0 will later be reissued with minor edits in 1998.
• HTML 4.01: In December 1999, HTML 4.01 was released.
• XHTML: The specifications for this was introduced in 2000 and
it was recommended to be used as the joint-standard with HTML
4.01. It incorporated XML to ensure code is properly written and
to ensure interoperability between programming languages.
• HTML5: The W3C published HTML5 as a recommendation in
October 2014 and will later release HTML 5.1 in November
2016.
4
Hypertext Markup Language (HTML)
describes the content and structure of information on a
web page
A markup language, i.e. it’s used to markup content.
Composed of several tags.
not the same as the presentation (appearance on screen)
surrounds text content with opening and closing tags
each tag's name is called an element
syntax: <element> content </element>
example: <p>This is a paragraph</p>
5 Web Programming
HTML Document
A text document containing markup tags
The tags tell the browser how to display the document
Should have an .htm or .html file name extension
Can be created using a simple text editor
6 Web Programming
Choosing Your HTML Editor
• If you will be creating web pages in HTML, you will need
an HTML editor.
• There are many free and paid HTML editors, and below
are some of the top options you can choose from:
• HTML-Kit
• CoffeeCup
• KompoZer
• Komodo Edit
• Notepad++
• Bluefish
HTML – Document Structure
An HTML document has the following basic structure:
<html>
<head>
<title>page title</title>
</head>
<body>
</body>
</html>
8 Web Programming
XHTML
a newer version of HTML, standardized in 2000
uses a markup format called XML (XML + HTML =
XHTML)
XHTML stands
forEXtensible HyperText Markup Language and is the next
step in the evolution of the Internet.
The XHTML 1.0 is the first document type in the XHTML
family.
9 Web Programming
though the browser will accept some malformed HTML,
we'll write "strict" XHTML that complies to the official
web standards
a strict XHTML page uses some different syntax and tags
XHTML is almost identical to HTML 4.01 with only few
differences.
This is a cleaner and more strict version of HTML 4.01.
10 Web Programming
XHTML was created for two main reasons:
11 Web Programming
The Main Changes:
There are several main changes in XHTML from HTML:
XHTML document must have a DOCTYPE declaration at
the top of the document.
All XHTML tags and attributes should be written in lower
case only.
All the XHTML tags will have their closing tags.
All the attribute values must be quoted.
Attribute minimization is forbidden.
The id attribute replaces the name attribute.
The language attribute of the script tag is deprecated
All the tags should be properly nested
13 Web Programming
If you want to use XHTML 1.0 Strict DTD then you need
to put following line at the top of your XHTML
document.
14 Web Programming
XHTML 1.0 Transitional:
If you are planning to use many XHTML attributes as well as few
Cascading Style Sheet properties, then you should adopt this DTD and you
should write your XHTML document according to DTD.
This DTD contains all HTML elements and attributes, INCLUDING
presentational and deprecated elements (like font). Framesets are not
allowed. The markup must also be written as well-formed XML.
If you want to use XHTML 1.0 Transitional DTD then you need to put the
following line at the top of your XHTML document
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
15 Web Programming
XHTML 1.0 Frameset:
This DTD is equal to XHTML 1.0 Transitional, but allows the
use of frameset content.
You can use this when you want to use HTML Frames to
partition the browser window into two or more frames.
If you want to use XHTML 1.0 Frameset DTD then you need
to put the following line at the top of your XHTML document.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
frameset.dtd">
NOTE: No matter what DTD you are using to write your XHTML
document, if it is a valid XHTML document then your document will be
considered as a good quality document.
16 Web Programming
Case Sensitivity:
XHTML is case sensitive markup language, more strictly
all the XHTML tags and attributes should be written in
lower case only. Here is the example, this is wrong
because Href and anchor A are having characters which
are not in lower case.
<!-- This is invalid in XHTML -->
<A Href="/xhtml/xhtml_tutorial.html">XHTML Tutorial</A>
<!-- Correct XHTML way of writing this is as follows -->
<a href="/xhtml/xhtml_tutorial.html">XHTML Tutorial</a>
17 Web Programming
Closing Tags:
Each and every XHTML tag should have an equivalent
closing tags, even empty elements should also have
closing tags. Here is the example showing the difference:
<!-- This is invalid in XHTML -->
18 Web Programming
Below is the correct way of writing above tags in
XHTML. Difference is that, here we have closed both the
tags properly.
<!-- This is valid in XHTML -->
<p>This paragraph is not written according to XHTML syntax.</p>
<!-- This is also valid now -->
<img src="/images/xhtml.gif" />
19 Web Programming
Attribute Quotes:
All the XHTML attribute values must be quoted otherwise
your XHTML document will be assumed as an invalid
document. Here is the example showing the difference.
20 Web Programming
Attribute Minimization:
XHTML does not allow attribute minimization. It means
you should explicitly state the attribute and the value.
Following is the example showing the difference:
<!-- This is invalid in XHTML -->
<option selected>
<!-- Correct XHTML way of writing this is as follows -->
<option selected="selected">
21 Web Programming
The id Attribute:
The id attribute replaces the name attribute. Instead of
using name="name", XHTML prefer to use id="id".
Following is the example to show this difference:
<!-- This is invalid in XHTML -->
<img src="/images/xhtml.gif" name="xhtml_logo" />
<!-- Correct XHTML way of writing this is as follows --> <img
src="/images/xhtml.gif" id="xhtml_logo" />
22 Web Programming
The Language Attribute:
The language attribute of the script tag is deprecated.
Following is the example showing this difference:
24 Web Programming
Structure of an XHTML page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/TR/xhtml1" xml:lang="en" lang="en">
<head>
<title>
Every document must have a title
</title>
</head>
<body>
...your content goes here...
</body>
</html>
25 Web Programming
(X)HTML Elements
Names enclosed in < and >
Have a start tag and end tag
Start tag format: <tag_name>
End tag format: </tag_name> [ note the / after < ]
E.g. <strong>bold text</strong>
HTML elements are Not case sensitive
XHTML elements are case sensitive
26 Web Programming
Building XHTML Documents
Elements consist of a start tag, content and an end tag:
Start Tag Content End Tag
Empty elements are used to describe elements that do not have any
content: <br />
Attributes are used to describe elements and are placed inside the open
tag of an element:
<img src=“picture.jpg” alt= “This is my picture” />
Comments are used to annotate the document, but are not processed
by parsers:
<!-- This is a comment -->
27
some tags can contain additional information called attributes
syntax: <element attribute="value" attribute="value">
content </element>
example:
<a href="page2.html">Next page</a>
E.g. <font face=“arial” size=“9”>Hello</font>
some tags don't contain content; can be opened and closed in
one tag
syntax: <element attribute="value" attribute="value" />
example: <hr />
example: <img src="bunny.jpg" alt="pic from Easter" />
28 Web Programming
Structure of XHTML
Documents
Documents consist of three parts:
1. Document Type Declaration
2. Header
3. Body
1 <?xml version=”1.0”?>
1 <?xml version=”1.0”?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2 <!DOCTYPE"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns=”http://www.w3.org/1999/xhtml”>
3
Root Element 4 xmlns=”http://www.w3.org/1999/xhtml”>
<html <head>
4 5
<head> <title>Strict XHTML Document</title>
5 6<title>Strict
</head> XHTML Document</title>
7 <body>
6 </head>
8 <!-- Body of document goes here -->
7 <body>
9 </body>
8 10<!--</html>
Body of document goes here -->
9 </body>
10 </html>
29
Document Framework Elements
The <html> element
• This is the root element for an XHTML document and must be present in every XHTML
document
• everything in the document should be within <html> &</html>
• The header and body elements are contained within the root <html> element
• Attributes: xmlns=http://www.w3.org/1999/xhtml
(Declares a namespace for custom tags in an HTML document.)
The <head> element
• Contains header elements that contain data used primarily by programs such as search engines
contains information which is not displayed in the browser display area
may contain other tags in it
Elements that can be contained within the <head> element:
<title> - Title of the document
<base> - Base URL of the document
<link> - Defines document relationship to other documents
<meta> - Contains information about document such as keywords, author information and
content type
<script> - Defines link to scripts used in the document
<style> - Defines links to style sheets used in the document
30
HTML Tags (cont’d)
body
contains the visible part of the web page
displayed in the display area of the browser
contains several other tags and content in it
format: <body>…</body>
attributes:
bgcolor=“color”
background=“img url”
text=“text color”
link=“link color”
alink=“active link color”
vlink=“visited link color”
…
31 Web Programming
Exercise : Hello World
32 Web Programming
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>My First Web page</title>
</head>
<body>
Hello World!
</body>
</html>
33 Web Programming
3.Save it with file name: hello.html (in My Documents)
4. Open My Documents folder
5. Find and open (double-click) hello.html
34 Web Programming
Basic Formatting Elements
Block Level Elements :
Used to describe blocks of content and to label the main content
headings
35
Block Level Elements
<p>…</p> - Paragraph element
<p> This is a paragraph </p>
36
HTML/XHTML Tags (cont’d)
headings
predefined formats for text presentation
headings to separate major areas of the page
six heading formats defined in HTML: <h1> up to <h6>
<h1> the largest font size
<h6> the smallest font size
Format:
<h1>…</h1>
E.g. <h2>a text in heading two</h2>
37 Web Programming
Eg:
<h1>Addis Ababa University </h1>
<h2>College of Natural Sciences</h2>
<h3>Department of Computer Science</h3>
38 Web Programming
paragraph
defines a paragraph
Format: <p>…</p>
<p>You're not your job.
You're not how much money you have in the bank.
You're not the car you drive. You're not the contents
of your wallet. You're the all-singing, all-dancing crap of the
world.</p>
39 Web Programming
HTML Tags (cont’d)
E.g. <p>this is a paragraph of text. it has a new line before and
after it.</p>
The browser inserts a new line before and after the text in the
paragraph tag.
attribute:
align=“alignment” {left, right, center, justify}
40 Web Programming
HTML Tags (cont’d)
horizontal rule
inserts a horizontal line
a horizontal line to visually separate sections of a page
Format: <hr />
attributes:
width=“width” {absolute: in pixels or relative: in %}
noshade=“noshade”
color=“color” {browser dependent}
E.g. <hr width=“75%” noshade=“noshade” color=“#FF0000”>
p>First paragraph</p>
<hr />
<p>Second paragraph</p>
41 Web Programming
Block Level Elements – XHTML Code
<?xml version=”1.0”?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>XHTML Block-level Elements</title>
</head>
<body>
<p> This is a paragraph about African Gray parrots. The African Gray is
one of the most popular pet birds of the parrot family. It is known
for its intellegence and is one of the best talkers of all domestic
birds. This parrot is native to Africa and can live to be almost 70
years old.</p>
<p> This is also a paragraph about African Gray parrots. Here is some
additional information about the African Gray parrot separated by
line breaks: (break here) <br />The African Gray parrot is about 15
inches long and (break here) <br />Has a wing span of about 20
inches.</p>
<hr />
<h1>This is a level 1 heading</h1>
<h2>This is a level 2 heading</h2>
<h3>This is a level 3 heading</h3>
<h4>This is a level 4 heading</h4>
<h5>This is a level 5 heading</h5>
<h6>This is a level 6 heading</h6>
<hr />
</body>
</html>
42
Block Level Elements – Web Browser
43
bold
makes a text appear in bold
Format: <b>…</b> or <strong>…</strong>
E.g. <b>a text in bold</b>
44 Web Programming
Presentational Formatting Elements
<b>…</b> - Bold font style
<b>This text is bold</b>
45
HTML Tags (cont’d)
underline
makes a text appear underlined
Format: <u>…</u>
E.g. <u>underlined text</u>
sub/sup
define either a subscript or a superscript
Format: <sub>…</sub> ; <sup>…</sup>
E.g. X<sub>1</sub><sup>2</sup> + 2X<sub>3</sub>
46 Web Programming
Comments: <!-- ... -->
HTML comments
insert commented text in an html document
Format: <!-- comment text -->
E.g. <!-- this is a comment text -->
<!-- My web page, by Suzy Student
CSE 190 D, Spring 2048 -->
<p>CSE courses are <!-- NOT --> a lot of fun!</p>
CSE courses are a lot of fun! text
47 Web Programming
Presentational Formatting Elements – XHTML Code
<?xml version=”1.0”?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>XHTML Presentational Text Formatting Elements</title>
</head>
<body>
<p>
This text is formatted in <b>bold</b>
</p>
<p>
This text is formatted in <i>italics</i>
</p>
<p>
See how <big>the big element</big> increases the current font size
and how <small>the small element</small>decreases it.
</p>
<p>
This is how the <sup>superscript element</sup>
and the element <sub>subscript element</sub> format text.
</p>
</body>
</html>
48
Block and inline elements (explanation)
block elements contain an entire large region of content
examples: paragraphs, lists, table cells
the browser places a margin of whitespace between block
elements for separation
inline elements affect a small amount of content
49 Web Programming
P text em text
text a text
50 Web Programming
Presentation Controls
All tags have associated attributes but many attributes (& tags)
have been deprecated with the move from HTML to XHTML
51
Logical Formatting Elements
<cite>…</cite> - Formats citation text
<cite>This text is bold</cite>
52
Logical Formatting Elements- XHTML Code
<?xml version=”1.0”?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>XHTML Logical Text Formatting Elements</title>
</head>
<body>
<p>
Following is a citation: <br />
<cite>
Four score and seven years ago, our fathers brought forth upon this continent a new
nation:
conceived in liberty, and dedicated to the proposition that all men are created equal.
</cite>
</p>
<p>
Following is a block of code: <br />
<code>
while ($x < 10) { <br />
$var = $x + 1; <br />
$count++; <br />
} <br />
</code>
</p>
<p> This text is formatted using the <strong>strong element</strong></p>
<p> This text is formatted using the <em>em element</em></p>
</body>
53 </html>
Logical Formatting Elements- Web browser
54
Ins and del tags
The ins(insert) tag is similar to u(underline tag), it is used
to show an inserted text
Eg
<p>The price of Shampoo is: <del
>100</del><ins>95</ins>
55 Web Programming
HTML Tags (cont’d)
lists
Unordered Lists (ul) (block)
define bulleted lists
ul represents a bulleted list of items (block)
li represents a single item within the list (block)
Format:
<ul>
<li>…</li>
<li>…</li>
…
</ul>
Atribute:
type=“bullet type” {disc, circle, square}
56 Web Programming
E.g.
<ul type=“square”> <li>book</li><li>marker</li><li>chalk</li></ul>
Eg.
<ul>
<li>No shoes</li>
<li>No shirt</li>
<li>No problem!</li>
</ul>
57 Web Programming
HTML Tags (cont’d)
Ordered Lists (ol)
define numbered lists
Format:
<ol>
<li>…</li>
<li>…</li>
…
</ol>
Atribute:
type=“number type” {1, i, I, a, A}
E.g.
<ol type=“i”> <li>book</li><li>marker</li><li>chalk</li></ol>
58 Web Programming
nested list
a list can contain other lists:
<ul>
<li>Colleges:
<ul>
<li>Natural Science</li>
<li>Social Science</li>
</ul>
</li>
<li>Schools:
<ul>
<li>Information Sceince</li>
<li>Medicine</li>
</ul>
</li>
</ul>
59 Web Programming
Class Activity: Create the following list
60
HTML Tags (cont’d)
Definition Lists <dl>, <dt>, <dd>
define a list of term-description pairs
dl represents a list of definitions of terms (block)
dt represents each term, and dd its definition
Format:
<dl>
<dt>…</dt>
<dd>…</dd>
<dt>…</dt>
<dd>…</dd>
…
</dl>
E.g.
<dl>
61 Web Programming
<dl>
<dt>book</dt>
<dd>something that we read …</dd>
<dt>marker</dt>
<dd>something we write with …</dd>
</dl>
62 Web Programming
Definition Lists
<dl> for list element; <dt> for “definition terms”; <dd>
for “definition data”
Example
<dl>
<dt><strong>CPU</strong></dt>
<dd>Central Processing Unit</dd>
<dt><strong>ALU</strong></dt>
<dd>Arithmetic Logic Unit</dd>
<dt><strong>GHz</strong></dt>
<dd>Gigahertz</dd>
</dl>
Quotations: <blockquote>
a lengthy quotation (block)
<p>As Lincoln said in his famous Gettysburg Address:</p>
<blockquote>
<p>Fourscore and seven years ago, our fathers brought forth
on this continent a new nation, conceived in liberty, and
dedicated to the proposition that all men are created equal.</p>
</blockquote>
As Lincoln said in his famous Gettysburg Address:
Fourscore and seven years ago, our fathers brought forth on this continent a
new nation,conceived in liberty, and dedicated to the proposition that all
men are created equal.
64 Web Programming
Inline quotations: <q>
a short quotation (inline)
65 Web Programming
Image File Formats
Three primary formats for Web images:
GIF – Graphics Interchange Format
The GIF format supports 256 colors and is a good format for small
non-photographic images like icons and buttons
JPEG - Joint Photographic Experts Group
JPEG is a compression technique that is used to reduce large file
sizes for high quality images, like photographs
PNG - Portable Network Graphics
PNG was originally developed to replace the GIF format. The
biggest difference between PNG and GIF is that PNG supports more
than 256 colors
The next slide will demonstrate the differences in image quality and file
sizes for these 3 formats. Notice that the GIF file is much more grainy than
the JPEG and PNG files. This is due to the restriction to only 256 colors.
66
Image File Formats Example
Original file – Windows Bitmap file – Stage.bmp File Size – 351k
68 Web Programming
The <img> element
The <img> element is an empty element
alt – Defines alternate text for the image file that will
display in place of the image if the client can not
display images
Title-Defines description to the image and it is displayed when we hover of the
image using mouse
69
Image- code
70
File organisation
The previous example assumes the image file is in the same
folder as html file
But web sites can get complicated and they are much easier to
manage if your files are organised into folders
Eg
71
Link Types
Link to other pages within site
72
Creating XHTML Links
The anchor element - <a>
Requires the user to perform an action in order to activate the link.
73
Creating XHTML Links
Relative vs. Absolute URL’s
Relative links are used to link to documents that reside on
the same Web server,
so the protocol and domain name reference can be omitted
from the URL:
74
Linking With the <img> Element
To use the <img> element as a link:
Embed the <img> element within an <a> element
By default, web browsers place a blue border around the image to identify it
as a clickable object
To remove the blue border around the image, use a style definition. This is
usually done in a cascading style sheet.(CSS) This will be covered later in the
course.
75
XHTML Links code
<?xml version=”1.0”?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>Link Examples in XHTML</title>
</head>
<body>
<p> Here are some examples of links in XHTML: </p>
<p><a href=”http://chughes.com/newpage.html”>This is an absolute link
to a new
page</a></p>
<p><a href=”newpage.html”>This is a relative link to a new
page</a></p>
<p><a href=”newpage.html”><img src=”button.gif” alt=”This image is a
clickable button”></a></p>
<p><a href=”mailto:[email protected]”>This is link that launches an
email message</a></p>
</body>
</html>
76
Linking within a single document
Links can be created to reference different sections of a single document
using internal links and anchors:
Use an anchor to mark a section in the document where you would like
to link to:
<a name=”footnote”>Footnote</a>
Use an internal link to reference the anchored section. Internal links
begin with a “#” character:
77
Linking within a single document - code
Named anchor
78
Linking within a single document – web browser
79
Class Activity
1. Create the following web page using Textpad, validate your code and then view in a browser.
Links to Act3_Q1.html
Links to Act4_Q1.html
80
HTML Tags (cont’d)
Anchors or Links: <a>
links, or "anchors", to other pages (inline)
defines a hyperlink or a named anchor
used for navigation
Format: <a>…</a>
Attributes:
href=“url”
uses the href attribute to specify the destination URL
target=“target” { _self, _blank }
name=“anchor name”
E.g.
<a href=“home.htm”>Go to home</a>
<a href=“http://www.google.com” target=“_blank”>Google</a>
81 Web Programming
HTML Tags (cont’d)
Navigation with anchors
named anchors
named places in an html document
Format: <a name=“anchor_name”></a>
E.g. <a name=“top”></a>
linking to anchors
Format:
<a href=“#anchor_name”>link text</a> {on the same page}
<a href=“http://www.aau.edu.et/history.htm#establishment”>
Establishment of AAU</a>
82 Web Programming
More about anchors
Lecture Notes 1
Google
83 Web Programming
Creating image map
<img src="./images/back.jpg" alt="Schedule is missing from
here.." width="400px" height="400px"
usemap="#mymap"/>
<map name="mymap">
<area shape="rect" coords="0,0,100,100" alt="Google"
title="Go to google" href="http://wwww.google.com" />
<area shape="circle" coords="200,200,100" alt="yahoo"
title="Go to hayoo" href="http://www.yahoo.com" />
</map>
84 Web Programming
Phrase elements : <em>, <strong>
em: emphasized text (usually rendered in italic)
strong: strongly emphasized text (usually rendered in
bold)
Example:
<p>
HTML is <em>really</em>,
<strong>REALLY</strong> fun!
</p>
85 Web Programming
Computer code: <code>
code: a short section of computer code (usually rendered in a
fixed-width font)
<p>
The <code>ul</code> and <code>ol</code>
tags make lists.
</p>
The ul and ol tags make lists.
86 Web Programming
Preformatted text: <pre>
<pre>
Steve Jobs speaks loudly
reality distortion
Apple fans bow down
</pre>
87 Web Programming
Using pre and code together
<pre><code>
public static void main(String[] args) {
System.out.println("Hello, world!");
}
</code></pre>
88 Web Programming
HTML Tags (cont’d)
Tables
insert tabular data
design page layout
Tags involved: <table><thead><tbody>, <tr>, <td>,
<th>, <caption>
89 Web Programming
XHTML Tables
XHTML tables are sets of elements used to format
content, or even an entire document, into rows and
columns
Tables can contain any type of content, including text,
links, images, and multimedia
Tables in XHTML work much the way they do in a
spreadsheet or word processing application and
resemble a grid
Tables can be used to format blocks of content or they
can also be used to providing formatting for an entire
document
90
Table Elements
<table> - Encloses the rest of the table elements
91
HTML Tags (cont’d)
Format:
<table>
<caption>table caption</caption>
<tr>
<td>…</td> <td>…</td> …
</tr>
<tr>
<td>…</td> <td>…</td> …
</tr>
…
</table>
92 Web Programming
Tables
By default
Text in each cell is automatically aligned to the left
All the cells in a column have the same width
Width of the column is determined by the cell with the most
text in it
<th> for “table header”
<tr>
<th>Header1</th>
<th>Header2</th>
</tr>
HTML Tags (cont’d)
E.g.
<table>
<caption align=“center” valign=“bottom”>table 1.0</caption>
<tr>
<th>Column 1</th> <th>Column 2</th>
</tr>
<tr>
<td>Cell 1</td> <td>Cell2</td>
</tr>
<tr>
<td>Cell 3</td> <td>Cell 4</td>
</tr>
</table>
94 Web Programming
Table- code
95
HTML Tags (cont’d)
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}
cellpadding=“padding amount” {in pixels}
…
96 Web Programming
HTML Tags (cont’d)
Table row attributes:
align=“alignment” {left, center, right}
bgcolor=“color”
height=“height”
valign=“alignment” {top, middle, bottom}
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.
97 Web Programming
<table> Common Element Attributes
Name Description and Values
border Sets the width of the border around the table. Values: A value of 0 makes the
border invisible. An integer value greater than 0 will result in a border of that number of
pixels.
cellpadding Sets the amount of space between the border of the table cell and the data
contained in the cell.
Values: Percentage or pixels
98
Table – code with attributes
Attributes have a
name and a value –
the value is written in
double quotes in
lowercase
99
<td> and <th> Element Attributes
Name Description and Values
headers List of cells that provide header information for the current cell based on the values of the id
attributes of the header cells. This list is space delimited.
scope Provides information about which cells the current header cell provides header information for
Values: col, colspan, row, rowspan
100
<tr> Element Attributes
Name Description and Values
101
Class Activity
1. Create the following web page using Notpad, validate your code and then view in a browser.
Now modify your code so the web page looks like this
102
Class Activity
3. Create the following web page using Notpad, validate your code and then view in a browser.
103
Long Tables
There are three elements that help distinguish between
the main content of the table and the first and last
rows (which can contain different content).
For long tables you can split the table into a <thead>,
<tbody>, and <tfoot>.
<thead>
The headings of the table should
sit inside the <thead> element.
<tfoot>
The footer belongs inside the <tfoot> element.
E.g. (colspan)
<table>
<tr> <td colspan=“2”>Cell 1</td> <td>Cell 2</td> <td>Cell 3</td> </tr>
<tr> <td>Cell 4</td> <td>Cell 5</td> <td>Cell 6</td> <td>Cell 7</td> </tr>
<tr> <td colspan=“4”>Cell 8</td> </tr>
</table>
E.g. (hybrid)
<table>
<tr> <th colspan=“3”>Title</th> </tr>
<tr> <th rowspan=“3”>Cell 1</th> <td>Cell 2</td> <td>Cell 3</td> </tr>
<tr> <td>Cell 4</td> <td>Cell 5</td> </tr>
<tr> <td>Cell 6</td> <td>Cell 7</td> </tr>
</table>
Solution:
<p> <a href="http://google.com/search?q=marty&ie=utf-8&aq=t">
Search Google for Marty </a> </p>
114
XHTML Forms
115
Overview of XHTML Forms
Web forms give Website owners the ability to receive information from their
users or to allow users to personalize the Website
Form input values are processed by a program on the Web server and usually
send another XHTML page back to the Web browser with either a set of
results based on the user’s input, or a confirmation page
Forms can be located anywhere in the body of an XHTML document
116
The <form> Element
The <form> - element contains all of the input elements of the form
Attributes:
◦ action – This attribute is required and provides the path to the
program that will process the form data when the user submits the form
◦ Examples:
<form action=”/cgi-bin/process.cgi”>
<form action=”http://www.grahamm.com/cgi-bin/process.cgi”>
<form action=”mailto:[email protected]”>
◦ method – This attribute tells the web server how to process the data
Values:
get – This is the default value and will automatically assign this value if the
method attribute is not present in the <form> element. This method appends
the form input data to the end of a URL.
The following two <form> start tags are the same:
<form action=”/cgi-bin/process.cgi” method=”get”>
<form action=”/cgi-bin/process.cgi”>
post – This value tells the processing program to send the form data to the server
as regular input data. Nothing will be appended to the URL
117
Get Versus Post
GET : asks a server for a page or data
for small and non-secure data
Is the default method
Data is sent as part of the request URL
Limitation in size of data
if request has parameters, they are sent in the URL as a query string
POST : submits data to a web server and retrieves the server's response
For large & secure data
Input is sent as a data stream after the request URL
if request has parameters, they are embedded in the request packet, not the URL
For submitting data, a POST request is more appropriate than a GET
GET requests embed their parameters in their URLs
URLs are limited in length (~ 1024 characters)
URLs cannot contain special characters without encoding
private data in a URL can be seen or modified by users
119
Text input elements - attributes
The following attributes can be used with text input elements:
maxlength - Maximum number of characters allowed for input
name - Used to identify the input field
size - Defines the size of the input field in characters. If this is smaller than
the maxlength attribute, the field will scroll.
size attribute controls onscreen width of text field
maxlength limits how many characters user is able to type into field
type - Defines the type of input (text, password, or file for text input fields)
disabled - Disables the field for user input. The value of a disabled field
will not be sent to the processing program
readonly - Makes the content of the text field unchangable. The value of this field
will be sent to the processing program
onselect - For use with scripts. An event handle that specifies an action to be
performed when the field is selected
onchange - For use with scripts. An event handle that specifies an action to be
performed when the content of the field has been changed
120
Example:
Student ID:<input type="text" size="10" maxlength="8" /> <br />
Password:<input type="password" size="16" />
<input type="submit" value="Log In" />
122
Example:Checkboxes
The XHTML language provides a means to submit the form using the program
that is specified in the action attribute of the <form> element by assigning the
value of “submit” to the type attribute for the <input /> element:
<input type=”submit” />
XHTML also gives users an ability to clear the form and reset the default
values by assigning the value of “reset” to the type attribute for the <input />
element:
<input type=”reset” />
The value attribute can be set to assign names to either of these buttons. If no
value is set, then the computer will assign default text
125
HTML Forms (cont’d)
Other input fields
<textarea> tag
a multi-line text input area (inline)
used to input a large block of text
Tag format: <textarea>…</textarea>
Attributes:
name=“name”
cols=“num_columns”
rows=“num_rows”
readonly=“readonly”
wrap=“wrap_type” {off, hard, soft, virtual, physical}
126
<textarea name="address" cols=30 rows=3>
optional text to appear in the textarea
</textarea>
(use wrap=physical within the tag to force wraparound)
Example:
<textarea rows="4" cols="20">
Type your comments here.
</textarea>
Attributes:
<legend>
align=“alignment” {left, center, right}
128
HTML File Upload
HTML File Upload is used to show the list of all file, when a user click on
browse button A form in an HTML (web page) contain an input element
with type="file". This involve one or more files into the submission of
form. The file are stored into hard disk of the web server, that is why file
input is called" file upload".
<input type="file">:The <input type="file> is used to create a upload file
with a text box and the browse button. The method attribute used in form
must be set to post
add a file upload to your form as an input tag with type of file
must also set the enctype attribute of the form
it makes sense that the form's request method must be post (an entire file can't
be put into a URL!)
form's enctype (data encoding type) must be set to multipart/form-data or else
the file will not arrive at the server
Example:
<label>First Name:
<input type=“text” name=“fname”>
</label>
submit button
133
Form Example – Web Browser
134
Class Activity
1. Create the following web page using Textpad, validate your code and then view in a browser.
135
Class Activity
2. Modify the form created in Question 1 and use a table to set the elements out more neatly, like
in the example below
136