HTML
HTML
3
Definitions
HTML first became an Internet standard in
1993.
Latest version of HTML is 4.01, released in
1999.
HTML documents are composed of tags.
The file extension for an HTML document
is .html or .htm .
Web server: the place where Web pages
are located.
4
Definitions
“Normal text” surrounded by
bracketed tags that tell browsers how
to display web pages
Pages end with “.htm” or “.html”
HTML Editor – A word processor that
has been specialized to make the
writing of HTML documents more
effortless.
5
Tags
7
Choosing Text Editor
HTML Editors are excellent tools for
experienced web developers; however; it is
important that you learn and understand the
HTML language so that you can edit code and
fix “bugs” in your pages.
For this Course, we will focus on using the
standard Microsoft Windows text editors,
NotePad. We may use also textpad.
8
Starting NotePad
NotePad is the standard text editor that
comes with the microsoft windows
operating system. To start NotePad in
windows 9x or XP follow the steps bellow:
Click on the “Start” button located on your
Windows task bar.
Click on “Programs” and then click on the
directory menu labeled “Accessories”.
Locate the shortcut “NotePad” and click the
shortcut once.
9
HTML Page Creation & Editing
In this chapter you will learn to create HTML
pages with a standard text editor.
Objectives
Upon completing this section, you should be
able to
1. Choose a Text Editor.
2. Create a Basic Starting Document.
3. Understand and set Document Properties.
4. View Your Results in a Browser.
10
Creating a Basic Starting Document
<HTML>
<HEAD>
<TITLE>Al al-Bayt University</TITLE>
</HEAD>
<BODY>
This is what is displayed.
</BODY>
</HTML>
11
Creating a Basic Starting Document
The HEAD of your document point to above
window part. The TITLE of your document
appears in the very top line of the user’s browser.
If the user chooses to “Bookmark” your page or
save as a “Favorite”; it is the TITLE that is added
to the list.
The text in your TITLE should be as descriptive as
possible because this is what many search
engines, on the internet, use for indexing your
site.
12
Setting Document Properties
13
Color Codes
• Colors are set using “RGB” color codes, which
are, represented as hexadecimal values. Each
2-digit section of the code represents the
amount, in sequence, of red, green or blue
that forms the color. For example, a RGB value
with 00 as the first two digits has no red in the
color.
14
Main Colours
15
RGB Colour Model
16
16 Basic Colors
17
Color Codes
1. WHITE 1. #FFFFFF
2. BLACK 2. #000000
3. RED 3. #FF0000
4. GREEN 4. #00FF00
5. BLUE 5. #0000FF
6. MAGENTA 6. #FF00FF
7. CYAN 7. #00FFFF
8. YELLOW 8. #FFFF00
9. AQUAMARINE 9. #70DB93
10. BAKER’S CHOCOLATE 10. #5C3317
11. VIOLET 11. #9F5F9F
12. BRASS 12. #B5A642
13. COPPER 13. #B87333
14. PINK 14. #FF6EC7
15. ORANGE 15. #FF7F00
18
Color Codes
If you require more information about color
values, there is an excellent site entitled
“VGDesign’s Interactive Color Cube” that
displays the background color code when you
put your cursor over a small color sample. The
Web address is :
http://www.vgdesign.com/color.html
19
The Body Element
• The BODY element of a web page is an important
element in regards to the page’s appearance. Here
are the attributes of the BODY tag to control all the
levels:
TEXT="#RRGGBB" to change the color of all the text
on the page (full page text color.)
This element contains information about the page’s
background color, the background image, as well as
the text and link colors.
20
Background Color
It is very common to see web pages with their
background color set to white or some other
colors.
To set your document’s background color, you
need to edit the <BODY> element by adding
the BGCOLOR attribute. The following example
will display a document with a white
background color:
<BODY BGCOLOR=“#FFFFFF”></BODY>
21
TEXT Color
The TEXT attribute is used to control the
color of all the normal text in the
document. The default color for text is
black. The TEXT attribute would be added
as follows:
<BODY BGCOLOR=“#FFFFFF”
TEXT=“#FF0000”></BODY>
In this example the document’s page
color is white and the text would be red.
22
LINK, VLINK, and ALINK
These attributes control the colors of the different link states:
1. LINK – initial appearance – default = Blue.
2. VLINK – visited link – default = Purple.
3. ALINK –active link being clicked–default= Yellow.
The Format for setting these attributes is:
<BODY BGCOLOR=“#FFFFFF” TEXT=“#FF0000”
LINK=“#0000FF”
VLINK=“#FF00FF”
ALINK=“FFFF00”> </BODY>
23
Using Image Background
The BODY element also gives you ability of
setting an image as the document’s background.
An example of a background image’s HTML code
is as follows:
<BODY BACKGROUND=“hi.gif”
BGCOLOR=“#FFFFFF”></BODY>
24
Previewing Your Work
Once you have created your basic starting
document and set your document properties it is a
good idea to save your file.
To save a file, in NotePad, follow these steps:
1. Locate and click on the menu called “File”.
2. Select the option under File Menu labeled “Save
As”.
3. In the “File Name” text box, type in the entire
name of your file (including the extension
name .html).
25
Edit, Save and View Cycle
To preview Your Work, open a web browser and do the
following:
1. Click on the menu labeled “File”.
2. Locate the menu option, “Open”.
26
Edit, Save and View Cycle
3. In the “Open” dialog box, click on the “Browse”
button and locate your web document.
4. Click “OK” once you have selected your file.
27
Headings, Paragraphs, Breaks & Horizontal Rules
28
Headings, <Hx> </Hx>
Inside the BODY element, heading elements H1
through H6 are generally used for major divisions
of the document. Headings are permitted to
appear in any order, but you will obtain the best
results when your documents are displayed in a
browser if you follow these guidelines:
1. H1: should be used as the highest level of heading, H2 as
the next highest, and so forth.
2. You should not skip heading levels: e.g., an H3 should not
appear after an H1, unless there is an H2 between them.
29
Headings, <Hx> </Hx>
<HTML>
<HEAD>
<TITLE> Example Page</TITLE>
</HEAD>
<BODY>
<H1> Heading 1 </H1>
Heading 1
<H2> Heading 2 </H2> Heading 2
<H3> Heading 3 </H3>
<H4> Heading 4 </H4> Heading 3
<H5> Heading 5 </H5> Heading 4
<H6> Heading 6 </H6> Heading 5
</BODY> Heading 6
</HTML>
30
Paragraphs, <P> </P>
Paragraphs allow you to add text to a
document in such a way that it will
automatically adjust the end of line to suite
the window size of the browser in which it is
being displayed. Each line of text will stretch
the entire length of the window.
31
Paragraphs, <P> </P>
<HTML><HEAD>
<TITLE> Example Page</TITLE> Heading 1
</HEAD> Paragraph 1,….
<BODY></H1> Heading 1 </H1>
<P> Paragraph 1, ….</P>
<H2> Heading 2 </H2>
Heading 2
Paragraph 2,….
<P> Paragraph 2, ….</P>
<H3> Heading 3 </H3>
<P> Paragraph 3, ….</P>
Heading 3
Paragraph 3,….
<H4> Heading 4 </H4>
<P> Paragraph 4, ….</P> Heading 4
<H5> Heading 5 </H5> Paragraph 4,….
<P> Paragraph 5, ….</P>
<H6> Heading 6</H6>
Heading 5
<P> Paragraph 6, ….</P> Paragraph 5,….
</BODY></HTML> Heading 6
Paragraph 6,….
32
Break, <BR>
Line breaks allow you to decide where the text will
break on a line or continue to the end of the
window.
A <BR> is an empty Element, meaning that it may
contain attributes but it does not contain content.
The <BR> element does not have a closing tag.
33
Break, <BR>
<HTML>
<HEAD>
<TITLE> Example Page</TITLE>
</HEAD>
<BODY> Heading 1
<H1> Heading 1 </H1> Paragraph 1,….
<P>Paragraph 1, <BR>
Line 2 <BR> Line 3 <BR>…. Line 2
</P> Line 3
</BODY> ….
</HTML>
34
Horizontal Rule, <HR>
The <HR> element causes the
browser to display a horizontal line
(rule) in your document.
<HR/> does not use a closing tag.
35
Horizontal Rule, <HR>
Attribute Description Default Value
Height of the rule in
SIZE 2 pixels
pixels
Width of the rule in
WIDTH pixels or percentage 100%
of screen width
Draw the rule with a Not set
NOSHADE flat look instead of a
3D look (3D look)
36
Horizontal Rule, <HR>
<HTML>
<HEAD>
<TITLE> Example Page</TITLE>
</HEAD>
<BODY> Heading 1
<H1> Heading 1 </H1> Paragraph 1,….
<P>Paragraph 1, <BR>
Line 2 <BR> Line 2
<HR>Line 3 <BR> _________________________
</P> __
</BODY>
Line 3
</HTML>
37
Character Formatting
In this chapter you will learn how to enhance your page with
Bold, Italics, and other character formatting options.
Objectives
Upon completing this section, you should be able to
1. Change the color and size of your text.
2. Use Common Character Formatting Elements.
3. Align your text.
4. Add special characters.
5. Use other character formatting elements.
38
Bold, Italic and other Character Formatting
Elements
<FONT SIZE=“+2”> Two sizes bigger</FONT>
The size attribute can be set as an absolute value from 1 to 7 or as
a relative value using the “+” or “-” sign. Normal text size is 3 (from
-2 to +4).
<B> Bold </B>
<I> Italic </I>
<U> Underline </U>
Color = “#RRGGBB” The COLOR attribute of the FONT element. E.g.,
<FONT COLOR=“#RRGGBB”>this text has color</FONT>
<PRE> Preformatted </PRE> Text enclosed by PRE tags is displayed
in a mono-spaced font. Spaces and line breaks are supported
without additional elements or special characters.
39
Bold, Italic and other Character Formatting
Elements
<EM> Emphasis </EM> Browsers usually display this
as italics.
<STRONG> STRONG </STRONG> Browsers display
this as bold.
<TT> TELETYPE </TT> Text is displayed in a mono-
spaced font. A typewriter text, e.g. fixed-width font.
<CITE> Citation </CITE> represents a document
citation (italics). For titles of books, films, etc.
Typically displayed in italics. (A Beginner's Guide to
HTML)
40
Bold, Italic and other Character Formatting
Elements
<P> <FONT SIZE=“+1”> One Size One Size Larger - Normal – One Size
Larger </FONT> - Normal – Smaller
<FONT SIZE=“-1”> One Size Smaller Bold - italics - Underlined -
</FONT> <BR> Colored
<B> Bold</B> - <I> italics</I> - <U> Emphasized - Strong - Tele Type
Underlined </U> -
<FONT COLOR=“#FF0000”> Colored
</FONT> <BR>
<EM> Emphasized</EM> -
<STRONG> Strong </STRONG> -
<TT> Tele Type </TT> <BR>
41
Alignment
Some elements have attributes for alignment
(ALIGN) e.g. Headings, Paragraphs and
Horizontal Rules.
The Three alignment values are : LEFT, RIGHT,
CENTER.
<CENTER></CENTER> Will center elements.
42
Alignment
43
Special Characters & Symbols
44
Special Characters & Symbols
Special Entity Special Entity
Character Name Character Name
Ampersand & & Greater-than > >
sign
Asterisk ∗ Less-than sign < <
∗∗
Cent sign ¢ ¢ Non-breaking
space
Copyright © © Quotation mark " "
Fraction one ¼ Registration ® ®
qtr ¼ mark
Fraction one ½ Trademark ™
45
half ½ sign ™
Special Characters & Symbols
• Additional escape sequences support accented
characters, such as:
• ö
– a lowercase o with an umlaut: ö
• ñ
– a lowercase n with a tilde: ñ
• È
– an uppercase E with a grave accent: È
NOTE: Unlike the rest of HTML, the escape sequences
are case sensitive. You cannot, for instance, use <
instead of <.
46
Additional Character Formatting Elements
47
Example
<P><STRIKE> strike-through text </STRIKE></BR>
48
Lists
49
List Elements
HTML supplies several list elements. Most list elements are
composed of one or more <LI> (List Item) elements.
UL : Unordered List. Items in this list start with a list mark
such as a bullet. Browsers will usually change the list mark in
nested lists.
<UL>
<LI> List item …</LI>
<LI> List item …</LI>
</UL>
• List item …
• List item …
50
List Elements
You have the choice of three bullet types: disc(default), circle,
square.
These are controlled in Netscape Navigator by the “TYPE”
attribute for the <UL> element.
<UL TYPE=“square”>
<LI> List item …</LI>
<LI> List item …</LI>
<LI> List item …</LI>
</UL>
List item …
List item …
List item …
51
List Elements
OL: Ordered List. Items in this list are numbered
automatically by the browser.
<OL>
<LI> List item …</LI>
<LI> List item …</LI>
<LI> List item …</LI>
</OL>
1. List item …
2. List item …
3. List item
You have the choice of setting the TYPE Attribute to one of
five numbering styles.
52
List Elements
TYPE Numbering Styles
1 Arabic numbers 1,2,3, ……
a Lower alpha a, b, c, ……
A Upper alpha A, B, C, ……
i Lower roman i, ii, iii, ……
I Upper roman I, II, III, ……
53
List Elements
You can specify a starting number for an ordered list.
<OL TYPE =“i”>
<LI> List item …</LI>
<LI> List item …</LI>
</OL>
<P> text ….</P>
<OL TYPE=“i” START=“3”>
<LI> List item …</LI>
</OL>
54
List Elements
i. List item …
ii. List item …
Text ….
55
List Elements
DL: Definition List. This kind of list is different from the
others. Each item in a DL consists of one or more Definition
Terms (DT elements), followed by one or more Definition
Description (DD elements).
<DL>
<DT> HTML </DT>
<DD> Hyper Text Markup Language </DD>
<DT> DOG </DT>
<DD> A human’s best friend!</DD>
</DL>
HTML
Hyper Text Markup Language
DOG
A human’s best friend!
56
Nesting Lists
You can nest lists by inserting a UL, OL, etc., inside a list item
(LI).
EXample
<UL TYPE = “square”>
<LI> List item …</LI>
<LI> List item …
<OL TYPE=“i” START=“3”>
<LI> List item …</LI>
<LI> List item …</LI>
<LI> List item …</LI>
<LI> List item …</LI>
<LI> List item …</LI>
</OL>
</LI>
<LI> List item …</LI> 57
What will be the output?
<H1 ALIGN="CENTER">SAFETY TIPS FOR CANOEISTS</H1>
<OL TYPE=“a” START=“2”>
<LI>Be able to swim </LI>
<LI>Wear a life jacket at all times </LI>
<LI>Don't stand up or move around. If canoe tips,
<UL>
<LI>Hang on to the canoe </LI>
<LI>Use the canoe for support and </LI>
<LI>Swim to shore
</UL> </LI>
<LI>Don't overexert yourself </LI>
<LI>Use a bow light at night </LI>
</OL>
58
The output….
59
<H1 ALIGN="CENTER">SAFETY TIPS FOR
CANOEISTS</H1>
<OL TYPE="a" START="2">
<LI>Be able to swim </LI>
<LI>Wear a life jacket at all times </LI>
<LI>Don't stand up or move around. If canoe tips,
<UL>
<LI>Hang on to the canoe </LI>
<LI>Use the canoe for support What
<OL type="I" start="4">
<LI> Be careful </LI>
will
<LI> Do not look around</LI> be the
</LI> </OL> output?
<LI>Swim to shore
</UL> </LI>
<LI>Don't overexert yourself </LI>
<LI>Use a bow light at night </LI>
</OL> 60
The output….
61
Images
In this chapter you will learn about images and
how to place images in your pages.
Objectives
Upon completing this section, you should be
able to
1. Add images to your pages.
62
Images
<IMG>This element defines a graphic image on the
page.
Image File (SRC:source): This value will be a URL
(location of the image) E.g.
http://www.domain.com/dir/file.ext or /dir/file.txt.
Alternate Text (ALT): This is a text field that
describes an image or acts as a label. It is displayed
when they position the cursor over a graphic image.
Alignment (ALIGN): This allows you to align the
image on your page.
63
Images
Width (WIDTH): is the width of the image in pixels.
Height (HEIGHT): is the height of the image in pixels.
Border (BORDER): is for a border around the image,
specified in pixels.
HSPACE: is for Horizontal Space on both sides of the
image specified in pixels. A setting of 5 will put 5 pixels of
invisible space on both sides of the image.
VSPACE: is for Vertical Space on top and bottom of the
image specified in pixels. A setting of 5 will put 5 pixels of
invisible space above and bellow the image.
64
Some Examples on images
1) <IMG SRC=“jordan.gif“ border=4>
2) <IMG SRC=" jordan.gif" width="60"
height="60">
3) <IMG SRC=“jordan.gif" ALT="This is a text
that goes with the image">
4) <IMG SRC=" jordan.gif “ Hspace="30"
Vspace="10" border=20>
5) < IMG SRC =" jordan.gif“ align="left">
blast blast blast blast blast
65
Anchors, URLs and Image Maps
In this chapter you will learn about Uniform Resource
Locator, and how to add them as Anchor or Links
inside your web pages.
Objectives
Upon completing this section, you should be able to
1. Insert links into documents.
2. Define Link Types.
3. Define URL.
4. List some commonly used URLs.
5. Plan an Image Map.
66
HOW TO MAKE A LINK
1) The tags used to produce links are the <A>
and </A>. The <A> tells where the link should start and
the </A> indicates where the link ends. Everything between
these two will work as a link.
67
More on LINKs
<body LINK="#C0C0C0" VLINK="#808080"
ALINK="#FF0000">
• LINK - standard link - to a page the visitor hasn't been to yet.
(standard color is blue - #0000FF).
VLINK - visited link - to a page the visitor has been to before.
(standard color is purple - #800080).
ALINK - active link - the color of the link when the mouse is
on it. (standard color is red - #FF0000).
If the programmer what to change the color
• Click <a href="http://www.yahoo.com"><font
color="FF00CC">here</font></a> to go to yahoo.
68
Internal Links
Internal Links : Links can also be created inside large documents to
simplify navigation. Today’s world wants to be able to get the
information quickly. Internal links can help you meet these goals.
1. Select some text at a place in the document that you would like to
create a link to, then add an anchor to link to like this:
<A NAME=“bookmark_name”></A>
The Name attribute of an anchor element specifies a location in the
document that we link to shortly. All NAME attributes in a
document must be unique.
2. Next select the text that you would like to create as a link to the
location created above.
<A HREF=“#bookmark_name”>Go To Book Mark</A>
69
E-Mail (Electronic Mail)
E.g. mailto:[email protected]
The type of service is identified as the mail client
program. This type of link will launch the users mail
client.
The recipient of the message is [email protected]
<A HREF=“mailto:[email protected]”>Send me
More Information </A>
70
Image Maps
Image maps are images, usually in gif format that have
been divided into regions; clicking in a region of the image
cause the web surfer to be connected to a new URL. Image
maps are graphical form of creating links between pages.
There are two type of image maps:
Client side and server side
Both types of image maps involve a listing of co-ordinates
that define the mapping regions and which URLs those
coordinates are associated with. This is known as the map
file.
71
Area Shapes Used
72
Client-Side Image Maps
Client-side image maps (USEMAP) use a map file that is part of
the HTML document (in an element called MAP), and is linked to
the image by the Web browser.
74
Tables
In this chapter you will learn that tables have many uses in
HTML.
Objectives:
Upon completing this section, you should be able to:
1. Insert a table.
2. Explain a table’s attributes.
3. Edit a table.
4. Add a table header.
75
Tables
The <TABLE></TABLE> element has four sub-
elements:
1. Table Row<TR></TR>.
2. Table Header <TH></TH>.
3. Table Data <TD></TD>.
4. Caption <CAPTION></CAPTION>.
The table row elements usually contain table
header elements or table data elements.
76
Tables
<table border=“1”>
<tr>
<th> Column 1 header </th>
<th> Column 2 header </th>
</tr>
<tr>
<td> Row1, Col1 </td>
<td> Row1, Col2 </td>
</tr>
<tr>
<td> Row2, Col1 </td>
<td> Row2, Col2 </td>
</tr>
</table>
77
Tables
78
Tables Attributes
BGColor: Some browsers support background colors
in a table.
Width: you can specify the table width as an
absolute number of pixels or a percentage of the
document width. You can set the width for the table
cells as well.
Border: You can choose a numerical value for the
border width, which specifies the border in pixels.
CellSpacing: Cell Spacing represents the space
between cells and is specified in pixels.
79
Table Attributes
CellPadding: Cell Padding is the space
between the cell border and the cell contents
and is specified in pixels.
Align: tables can have left, right, or center
alignment.
Background: Background Image, will be titled
in IE3.0 and above.
BorderColor, BorderColorDark.
80
Table Caption
A table caption allows you to specify a line of text
that will appear centered above or bellow the table.
<TABLE BORDER=1 CELLPADDING=2>
<CAPTION ALIGN=“BOTTOM”> Label For My Table </CAPTION>
81
Table Header
82
Table Data and Table Header Attributes
Colspan: Specifies how many cell columns of the table this cell
should span.
Rowspan: Specifies how many cell rows of the table this cell
should span.
Align: cell data can have left, right, or center alignment.
Valign: cell data can have top, middle, or bottom alignment.
Width: you can specify the width as an absolute number of
pixels or a percentage of the document width.
Height: You can specify the height as an absolute number of
pixels or a percentage of the document height.
83
Basic Table Code
<TABLE BORDER=1 width=50%>
<CAPTION> <h1>Spare Parts <h1> </Caption>
<TR><TH>Stock Number</TH><TH>Description</TH><TH>List Price</TH></TR>
<TR><TD bgcolor=red>3476-AB</TD><TD>76mm
Socket</TD><TD>45.00</TD></TR>
<TR><TD >3478-AB</TD><TD><font color=blue>78mm Socket</font>
</TD><TD>47.50</TD></TR>
<TR><TD>3480-AB</TD><TD>80mm Socket</TD><TD>50.00</TD></TR>
</TABLE>
84
Table Data and Table Header Attributes
85
Table Data and Table Header Attributes
Row 1 Col 1
Row 2 Col 2
Row 2 Col 1
Row 3 Col 2
86
Special Things to Note
• TH, TD and TR should always have end tags.
Although the end tags are formally optional, many browsers will mess
up the formatting of the table if you omit the end tags. In particular,
you should always use end tags if you have a TABLE within a TABLE --
in this situation, the table parser gets hopelessly confused if you don't
close your TH, TD and TR elements.
• A default TABLE has no borders
By default, tables are drawn without border lines. You need the
BORDER attribute to draw the lines.
• By default, a table is flush with the left margin
TABLEs are plopped over on the left margin. If you want centered
tables, You can either: place the table inside a DIV element with
attribute ALIGN="center".
Most current browsers also supports table alignment, using the ALIGN
attribute. Allowed values are "left", "right", or "center", for example:
<TABLE ALIGN="left">. The values "left" and "right" float the table to
the left or right of the page, with text flow allowed around the table.
This is entirely equivalent to IMG alignment
87
What will be the output?
89
<Embed >
You can put any media file in src attribute. You can try it yourself by giving
various files.
Attributes:
Following is the list of important attributes for <embed> element.
align - Determines how to align the object. It takes either center, left or right.
autostart - Indicates if the media should start automatically. Netscape default
is true, Internet Explorer is false.
loop - Specifies if the sound should be played continuously (set loop to true),
a certain number of times (a positive value) or not at all (false). This is
supported by Netscape only.
playcount - Specifies the number of times to play the sound. This is alternat
option for loop if you are usiong IE.
hidden - Defines if the object shows on the page. A false value means no and
true means yes.
<Embed>
height - Height of the object in pixels or en.
width - Width of the object in pixels or en.
pluginspage - Specifies the URL to get the plugin software.
name - A name used to reference the object.
src - URL of the object to be embedded. This can be any
recognizable by the user's browser. It could
be .mid, .wav, .mp3, .avi and so on).
volume - Controls volume of the sound. Can be from 0 (off) to
100 (full volume). This attribute is supported by Netscape
only.
HTML - Video Media Types
Flash movies (.swf), AVI's (.avi), and MOV's (.mov) file types are
supported by the embed tag;
.swf files - are the file types created by Macromedia's Flash
program.
.wmv files - are Microsoft's Window's Media Video file types.
.mov files - are Apple's Quick Time Movie format.
.mpeg files - are movie files created by the Moving Pictures
Expert Group.
95
Frames
Doc1.html Doc2.html
Doc1.html Doc2.html
Frames.html
96
Frame Page Architecture
A <FRAMESET> element is placed in the html document
before the <BODY> element. The <FRAMESET>
describes the amount of screen real estate given to
each windowpane by dividing the screen into ROWS or
COLS.
The <FRAMESET> will then contain <FRAME> elements,
one per division of the browser window.
Note: Because there is no BODY container, FRAMESET
pages can't have background images and background
colors associated with them.
97
Frame Page Architecture
<HTML>
<HEAD>
<TITLE> Framed Page </TITLE>
<FRAMeSET COLS=“23%,77%”>
<FRAME SRC=“Doc1.html”>
<FRAME SRC=“Doc2.html”>
</FRAMeSET >
</HEAD>
</HTML>
98
The Diagram below is a graphical view of the
document described above
FRAME FRAME
NAME= NAME=right_pane
left_pane SRC= Doc2.html
SRC=Doc1.h
tml
99
<FRAMESET> Container
<FRAMESET> : The FRAMESET element creates divisions in
the browser window in a single direction. This allows you
to define divisions as either rows or columns.
ROWS : Determines the size and number of rectangular
rows within a <FRAMESET>. They are set from top of the
display area to the bottom.
Possible values are:
Absolute pixel units, I.e. “360,120”.
A percentage of screen height, e.g. “75%,25%”.
Proportional values using the asterisk (*). This is often
combined with a value in pixels , e.g. “360,*”.
<Frameset cols=“200,20%,*,2*”>
100
Creating a Frames Page
COLS: Determines the size and number of
rectangular columns within a <FRAMESET>. They are
set from left to right of the display area.
101
Creating a Frames Page
FRAMEBORDER : Possible values 0, 1, YES, NO. A setting
of zero will create a borderless frame.
FRAMESPACING: This attribute is specified in pixels. If you
go to borderless frames you will need to set this value to
zero as well, or you will have a gap between your frames
where the border used to be.
BORDER(thickness of the Frame): This attribute specified
in pixels. A setting of zero will create a borderless frame.
Default value is 5.
BORDERCOLOR: This attribute is allows you choose a color
for your border. This attribute is rarely used.
102
103
<FRAME>
<FRAME>: This element defines a single frame within a
frameset. There will be a FRAME element for each division
created by the FRAMESET element. This tag has the following
attributes:
SRC: Required, as it provides the URL for the page that will be
displayed in the frame.
NAME: Required for frames that will allow targeting by other
HTML documents. Works in conjunction with the target
attribute of the <A>, <AREA>, <BASE>, and <FORM> tags.
104
<FRAME>
MARGINWIDTH: Optional attribute stated in pixels.
Determines horizontal space between the <FRAME>
contents and the frame’s borders.
MARGINHEIGHT: Optional attribute stated in pixels.
Determines vertical space between the <FRAME>
contents and the frame’s borders.
SCROLLING: Displays a scroll bar(s) in the frame.
Possible values are:
1. Yes – always display scroll bar(s).
2. No – never display scroll bar(s).
3. Auto – browser will decide based on frame contents.
By default: scrolling is auto.
105
<FRAME>
106
<NOFRAMES>
<NOFRAMES>: Frame – capable browsers ignore all HTML
within this tag including the contents of the BODY element.
This element does not have any attributes.
<HTML>
<HEAD>
<TITLE> Framed Page </TITLE>
</HEAD>
107
<NOFRAMES>
<FRAMESET COLS="23%,77%">
<FRAME SRC="" NAME="left_pane“>
<FRAME SRC="" NAME="right_pane">
<NOFRAMES>
<P> This is a Framed Page. Upgrade your browser
to support frames.</P>
</NOFRAMES></FRAMESET>
108
Compound FRAMESET Divisions
109
Compound FRAMESET Divisions
<html> <noframes>
<head>
<p>
<title> Compound Frames Page</title>
Default
</head> message
<frameset rows=“120,*”>
<frame src=“banner_file.html” </p>
name”banner”> </noframes>
<frameset cols=“120,*”>
</frameset>
<frame src=“links_file.html”
name=“links”> </frameset>
<frame src=“content_file.html”
name=“content”> </head>
110
Compound FRAMESET Divisions
You may want to create a frames design with a
combination of rows and columns.
Banner File
Links
Contents File
File
111
Compound FRAMESET Divisions
Example
<HEAD>
<FRAMESET ROWS="25%,50%,25%”
<FRAME SRC="">
<FRAMESET COLS="25%,*">
<FRAME SRC="">
<FRAME SRC="">
</FRAMESET>
<FRAME SRC="">
</FRAMESET>
</HEAD>
112
Output
113
114
115
116
Frame Formatting
• Example:
117
118
119
What do the following mean?
1) <FRAMESET COLS="2*, 3*, 5*">
2) <FRAMESET COLS="150, 20%, *, 3*">
So what are the space-allocation priorities?
Absolute pixel values are always assigned
space first, in order from left to right. These
are followed by percentage values of the
total space. Finally, proportional values are
divided based upon what space is left.
120
Generic Frame Formula
• The <FRAME> tag has six associated attributes:
SRC, NAME, MARGINWIDTH, MARGINHEIGHT,
SCROLLING, and NORESIZE. Here's a complete
generic FRAME:
• <FRAME SRC="url" NAME="window_name"
SCROLLING=YES|NO|AUTO
MARGINWIDTH="value" MARGINHEIGHT="value"
NORESIZE>
121
What will be the Output?
<FRAMESET ROWS="*, 2*, *" COLS="2*, *">
<FRAME SRC=“”>
<FRAME SRC=“”>
<FRAME SRC=“”>
<FRAME SRC=“”>
<FRAME SRC=“”>
<FRAME SRC=“”>
</FRAMESET>
122
Targets
When you use links for use in a frames environment you will
need to specify an additional attribute called TARGET.
The TARGET attribute uses the NAME attribute of the FRAME
element.
If we were to place a link in doc1.html that linked to doc3.html
and we wanted doc3.html to be displayed in the right
windowpane; the HTML code would appear in doc1.html as
follows:
123
Special Targets
• There are 4 special target names that cannot be assigned by the
NAME attribute of the FRAME tag.
1. TARGET=“_top” : This loads the linked document into the full
browser window with the URL specified by the HREF attribute. All
frames disappear, leaving the new linked page to occupy the entire
window. The back is turned on.
2. TARGET=“_blank” : Opens an unnamed new browser window and
loads the document specified in the URL attribute into the new
window (and your old window stays open). The back is turned off.
Other windows remains on.
chap2.html
126
Targeting links to frames
The TARGET attribute allows you to specify the frame into which a page is to
be loaded into in a frames setting.
chap3.html
127
Forms
Forms add the ability to web pages to not only provide the person
viewing the document with dynamic information but also to obtain
information from the person viewing it, and process the
information.
Objectives:
Upon completing this section, you should be able to
1. Create a FORM.
2. Add elements to a FORM.
128
Forms
To insert a form we use the <FORM></FORM> tags. The rest of the form
elements must be inserted in between the form tags.
<HTML> <HEAD>
<TITLE> Sample Form</TITLE>
</HEAD>
<BODY BGCOLOR=“FFFFFF”>
<FORM ACTION = http://www.xnu.com/formtest.asp>
<P> First Name: <INPUT TYPE=“TEXT” NAME=“fname” MAXLENGTH=“50”> </P>
<P> <INPUT TYPE=“SUBMIT” NAME=“fsubmit1” VALUE=“Send Info”> </P>
</FORM>
</BODY> </HTML>
129
<FORM> element attributes
ACTION: is the URL of the CGI (Common Gateway
Interface) program that is going to accept the data
from the form, process it, and send a response
back to the browser.
METHOD: GET (default) or POST specifies which
HTTP method will be used to send the form’s
contents to the web server. The CGI application
should be written to accept the data from either
method.
NAME: is a form name used by VBScript or
JavaScripts.
TARGET: is the target frame where the response
page will show up.
130
Form Elements
Form elements have properties: Text boxes,
Password boxes, Checkboxes, Option(Radio)
buttons, Submit, Reset, File, Hidden and
Image.
The properties are specified in the TYPE
Attribute of the HTML element
<INPUT></INPUT>.
131
Sami Ali
Al al-Bayt University
132
Form Elements
<INPUT> Element’s Properties
TYPE= Type of INPUT entry field.
NAME = Variable name passed to CGI application
VALUE= The data associated with the variable
name to be passed to the CGI application
CHECKED= Button/box checked
SIZE= Number of visible characters in text field
MAXLENGHT= Maximum number of characters
accepted.
133
Text Box
Text boxes: Used to provide input fields for text, phone
numbers, dates, etc.
<INPUT TYPE= " TEXT " >
Browser will display
Textboxes use the following attributes:
TYPE: text.
SIZE: determines the size of the textbox in characters.
Default=20 characters.
MAXLENGHT : determines the maximum number of
characters that the field will accept.
NAME: is the name of the variable to be sent to the CGI
application.
VALUE: will display its contents as the default value.
134
Example on Text Box
<TITLE>Form_Text_Type</TITLE>
</HEAD> <BODY>
<h1> <font color=blue>Please enter the following
bioData</font></h1>
<FORM name="fome1" Method= " get " Action= " URL " >
First Name: <INPUT TYPE="TEXT" NAME="FName"
SIZE="15" MAXLENGTH="25"><BR>
Last Name: <INPUT TYPE="TEXT" NAME="LName"
SIZE="15" MAXLENGTH="25"><BR>
Nationality: <INPUT TYPE="TEXT" NAME="Country"
SIZE="25" MAXLENGTH="25"><BR>
The Phone Number: <INPUT TYPE="TEXT" NAME="Phone"
SIZE="15" MAXLENGTH="12"><BR>
</FORM> </BODY> </HTML>
135
Output
136
Password
Password: Used to allow entry of passwords.
<INPUT TYPE= " PASSWORD " >
Browser will display
Text typed in a password box is starred out in the browser
display.
Password boxes use the following attributes:
TYPE: password.
SIZE: determines the size of the textbox in characters.
MAXLENGHT: determines the maximum size of the password in
characters.
NAME: is the name of the variable to be sent to the CGI
application.
VALUE: is usually blank.
137
Example on Password Box
<HTML><HEAD>
<TITLE>Form_Password_Type</TITLE></HEAD>
<BODY>
<h1> <font color=red>To Access, Please
enter:</font></h1>
<FORM name="fome2" Action="url" method="get">
User Name: <INPUT TYPE="TEXT" Name="FName"
SIZE="15" MAXLENGTH="25"><BR>
Password: <INPUT TYPE="PASSWORD"
NAME="PWord" value="" SIZE="15”
MAXLENGTH="25"><BR>
</FORM></BODY> </HTML>
138
Output
139
Hidden
Hidden: Used to send data to the CGI application that
you don’t want the web surfer to see, change or have
to enter but is necessary for the application to process
the form correctly.
<INPUT TYPE=“HIDDEN”>
Nothing is displayed in the browser.
Hidden inputs have the following attributes:
TYPE: hidden.
NAME: is the name of the variable to be sent to the
CGI application.
VALUE: is usually set a value expected by the CGI
application.
140
Check Box
Check Box: Check boxes allow the users to select more
than one option.
<INPUT TYPE=“CHECKBOX”>
Browser will display
142
Output
143
Radio Button
Radio Button: Radio buttons allow the users to select
only one option.
<INPUT TYPE=“RADIO”>
Browser will display
144
<HTML> <HEAD><TITLE>CheckBoxType</TITLE> </HEAD>
<BODY>
<h1> <font color=green>Please check one of the
following</font></h1>
<FORM name="fome3" Action="url" method="get">
<font color=red> Select Country: </font><BR>
jordan:<INPUT TYPE= "RADIO" Name="country" CHECKED><BR>
Yemen<INPUT TYPE="RADIO " Name="country"><BR>
Qatar:<INPUT TYPE="RADIO" Name="country"><BR> <BR>
<font color=blue>Select Language:</font><BR>
Arabic:<INPUT TYPE="RADIO" Name="language" CHECKED><BR>
English:<INPUT TYPE=" RADIO " Name="language"><BR>
French:<INPUT TYPE=" RADIO " Name="language"> <BR></FORM>
</BODY></HTML>
145
146
<HTML><HEAD>
<TITLE>RADIOBox</TITLE> </HEAD>
<BODY>
Form #1:
<FORM>
<INPUT TYPE="radio" NAME="choice" VALUE="one"> Yes.
<INPUT TYPE="radio" NAME="choice" VALUE="two"> No.
</FORM>
<HR color=red size="10" >
Form #2:
<FORM>
<INPUT TYPE="radio" NAME="choice" VALUE="three" CHECKED>
Yes.
<INPUT TYPE="radio" NAME="choice" VALUE="four"> No.
</FORM>
</BODY></HTML>
147
Output
148
Push Button
Push Button: This element would be used with
JavaScript to cause an action to take place.
<INPUT TYPE=“BUTTON”>
Browser will display
149
<DIV align=center><BR><BR>
<FORM>
<FONT Color=red>
<h1>Press Here to see a baby crying:<BR>
<INPUT TYPE="button" VALUE="PressMe"><BR><BR>
<FONT Color=blue>
Click Here to see a baby shouting:<BR>
<INPUT TYPE="button" VALUE="ClickMe" > <BR><BR>
<FONT Color=green>
Hit Here to see a baby eating:<BR>
<INPUT TYPE="button" VALUE="HitME" > <BR><BR>
<FONT Color=yellow>
</FORM></DIV>
150
151
Submit Button
Submit: Every set of Form tags requires a Submit button.
This is the element causes the browser to send the names
and values of the other elements to the CGI Application
specified by the ACTION attribute of the FORM element.
<INPUT TYPE=“SUBMIT”>
The browser will display
Submit has the following attributes:
TYPE: submit.
NAME: value used by the CGI script for processing.
VALUE: determines the text label on the button, usually
Submit Query.
152
<FORM Action="URL" method="get">
First Name: <INPUT TYPE="TEXT" Size=25
name="firstName"><BR>
Family Name: <INPUT TYPE="TEXT" Size=25
name="LastName"><BR>
<BR>
<FONT Color=red>
Press Here to submit the data:<BR>
<INPUT TYPE="submit" VALUE="SubmitData " >
</FORM>
153
154
Reset Button
• Reset: It is a good idea to include one of these for
each form where users are entering data. It
allows the surfer to clear all the input in the form.
• <INPUT TYPE=“RESET”>
156
157
Image Submit Button
Image Submit Button: Allows you to substitute an
image for the standard submit button.
158
<form>
<H1><font color=blue>
Click to go Jordan’s Map:
<INPUT TYPE="IMAGE" SRC="jordan.gif">
</form>
159
File
• File Upload: You can use a file upload to allow surfers to
upload files to your web server.
• <INPUT TYPE=“FILE”>
• Browser will display
161
Other Elements used in Forms
163
164
165
166
Other Elements used in Forms
The two following examples are
<SELECT></SELECT> elements, where the
attributes are set differently.
The Select elements attributes are:
NAME: is the name of the variable to be sent to
the CGI application.
SIZE: this sets the number of visible choices.
MULTIPLE: the presence of this attribute signifies
that the user can make multiple selections. By
default only one selection is allowed.
167
<BODY bgcolor=lightblue>
<form>
Select the cities you have visited:
<SELECT name=“list” size=5>
<option> London</option>
<option> Tokyo</option>
<option> Paris</option>
<option> New York</option>
<option> LA</option>
<option> KL</option>
</SELECT>
</form>
</BODY>
168
169
Other Elements used in Forms
170
Other Elements used in Forms
List Box:
171
Other Elements used in Forms
Option
The list items are added to the <SELECT> element by
inserting <OPTION></OPTION> elements.
The Option Element’s attributes are:
SELECTED: When this attribute is present, the
option is selected when the document is initially
loaded. It is an error for more than one option to
be selected.
VALUE: Specifies the value the variable named in
the select element.
172
</HEAD>
<BODY>
<h2><font color=blue>What type of Computer do you
have?</font><h2>
<FORM>
<SELECT NAME="ComputerType" size=4>
<OPTION value="IBM" SELECTED> IBM</OPTION>
<OPTION value="INTEL"> INTEL</OPTION>
<OPTION value=" Apple"> Apple</OPTION>
<OPTION value="Compaq"> Compaq</OPTION>
</SELECT>
</FORM></BODY></HTML>
173
174
<HEAD> <TITLE>SELECT with Mutiple </TITLE> </HEAD>
<BODY>
<h2><font color=blue>What type of Computer do you
have?</font><h2>
<FORM>
<SELECT NAME="ComputerType" size=5 multiple>
<OPTION value="IBM" > IBM</OPTION>
<OPTION value="INTEL"> INTEL</OPTION>
<OPTION value=" Apple"> Apple</OPTION>
<OPTION value="Compaq" SELECTED> Compaq</OPTION>
<OPTION value=" other"> Other</OPTION>
</SELECT>
</FORM></BODY></HTML>
175
176
177
XHTML Document Type Definition (DTDs)
Three types of DTDs can be used with XHTML documents:
Transitional, Strict, and Frameset.
Deprecated elements are elements that are considered
obsolete and they will be eventually removed from a
language.
– Examples of deprecated HTML elements:
<applet>, <basefont>, <center>, <dir>, <menu>…
XHTML Document Type Definition (DTDs)
The World Wide Web Consortium (W3C) oversees the
development of Web technology standards.
A Transitional DTD allows the use of deprecated style tags
in HTML documents:
– <!DOCTYPE html PUBLIC
– “-//W3C//DTD XHTML 1.0 Transitional//EN”
XHTML Document Type Definition (DTDs)
“http://www/w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd”>
<body>
inline.html
14
15
16
(1 of 2)
<p>This text does not have any style applied to it.</p>
this method can only specify style information for the current
document:
– 1:1 relationship
– However, the same document may have other style
definitions applied to it
• 1:M relationship
embedded style sheet rule will have higher precedence than
external style sheet rule, if there is a conflict between styles
embedded style sheet rule will have lower precedence than an
inline style sheet rule
Embedded Style Sheets
declared.html
36 Deitel & Associates, Inc. is a member of the World Wide
37 Web Consortium. The company provides courses on Java,
38 C++, Visual Basic, C, Internet and World Wide Web
39
40
41 <h1>Clients</h1>
(2 of 3)
programming, and Object Technology.</p>
42 <p class = "special"> The company's clients include many Style Class “special”
43 <em>Fortune 1000 companies</em>, government agencies,
invoked for p element
44 branches of the military and business organizations.
45 Through its publishing partnership with Prentice Hall,
46 Deitel & Associates, Inc. publishes leading-edge
47 programming textbooks, professional books, interactive
48 CD-ROM-based multimedia Cyber Classrooms, satellite
49 courses and World Wide Web courses.</p>
50
51 </body>
52 </html>
a:hover
(1 ofelement
{ text-decoration: none }
3) a in this document
{ text-decoration: underline;
17 color: red;
Pseudoclass: applicable only to element
18 background-color: #ccffcc } a in this document. (note different syntax)
19
20 li em { color: red; This is NOT a group selector. It declares that this specific
21 font-weight: bold } style is applicable to em elements inside an li element
22
23 ul { margin-left: 75px }
24
25 ul ul { text-decoration: underline;
26 margin-left: 15px }
27
28 </style>
29 </head>
30
31 <body>
32
33 <h1>Shopping list for <em>Monday</em>:</h1>
34
35
36
37
<ul>
<li>Milk</li>
<li>Bread
advance.html
38
39
40
<ul>
<li>White bread</li>
<li>Rye bread</li>
(2 of 3)
41 <li>Whole wheat bread</li>
42 </ul>
43 </li>
44 <li>Rice</li>
45 <li>Potatoes</li>
46 <li>Pizza <em>with mushrooms</em></li>
47 </ul>
48
49 <p><a class = "nodec" href = "http://www.food.com">
50 Go to the Grocery store</a></p>
51
52 </body>
53 </html>
External Style Sheets
Location (href) and type (type) of the external style sheet are specified as
attributes of a link element in the head portion of an XHTML document
In addition, the rel attribute specifies the nature of the relationship
between the stylesheet and the document that is referencing it
– Persistent stylesheets must be applied to the document
– Preferred style sheet should be applied the unless the user has
selected a different alternate
– Alternate style sheets may be selected by users depending on
their preferences
Linking External Style Sheets
{ text-decoration: underline;
(1 of 1)
17 margin-left: .5cm }
1 <?xml version = "1.0"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
4
5 <!-- Fig. 6.5: external.html -->
6 <!-- Linking external style sheets -->
7
8 <html xmlns = "http://www.w3.org/1999/xhtml">
9 <head>
10 <title>Linking External Style Sheets</title>
11
12
13 </head>
href = "styles.css" /> external.html
<link rel = "stylesheet" type = "text/css"
14
15
16
<body> (1 of 2)
17 <h1>Shopping list for <em>Monday</em>:</h1>
18 <ul>
19 <li>Milk</li>
20 <li>Bread
21 <ul>
22 <li>White bread</li>
23 <li>Rye bread</li>
24 <li>Whole wheat bread</li>
25 </ul>
26 </li>
27 <li>Rice</li>
28 <li>Potatoes</li>
29 <li>Pizza <em>with mushrooms</em></li>
30 </ul>
31
32 <p>
33 <a href = "http://www.food.com">Go to the Grocery store</a>
34 </p>
35
36 </body>
37 </html>
W3C CSS Validation Service
Validates external CSS documents
Ensures that style sheets are syntactically correct
http://jigsaw.w3.org/css-validator/
6.10 Text Flow and the Box Model
Floating
– Move an element to one side of the screen
Box model
– Margins
– Padding
– Border
1 <?xml version = "1.0"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
4
5 <!-- Fig. 6.12: floating.html -->
6 <!-- Floating elements and element boxes -->
7
8 <html xmlns = "http://www.w3.org/1999/xhtml">
9 <head>
10 <title>Flowing Text Around Floating Elements</title>
11
12 <style type = "text/css"> floating.html
(1 of 3)
13
14 div { background-color: #ffccff;
15 margin-bottom: .5em;
16 font-size: 1.5em;
17 width: 50% }
18
19 p { text-align: justify }
20
21 </style>
22
23 </head>
24
25 <body>
26
27 <div style = "text-align: center">
28 Deitel & Associates, Inc.</div>
29
30 <div style = "float: right; margin: .5em;
31 text-align: right">
32 Corporate Training and Publishing</div>
33
34 <p>Deitel & Associates, Inc. is an internationally
35
36
37
floating.html
recognized corporate training and publishing organization
specializing in programming languages, Internet/World
(2 of 3)
Wide Web technology and object technology education.
38 The company provides courses on Java, C++, Visual Basic, C,
39 Internet and World Wide Web programming, and Object Technology.</p>
40
41 <div style = "float: right; padding: .5em;
42 text-align: right">
43 Leading-Edge Programming Textbooks</div>
44
45 <p>The company's clients include many Fortune 1000
46 companies, government agencies, branches of the military
47 and business organizations.</p>
48
49 <p style = "clear: right">Through its publishing
50 partnership with Prentice Hall, Deitel & Associates,
51 Inc. publishes leading-edge programming textbooks,
52 professional books, interactive CD-ROM-based multimedia
53 Cyber Classrooms, satellite courses and World Wide Web
54 courses.</p>
55
56 </body>
57 </html>
Text Flow and the Box Model
Ma rg in
Bo rd e r
C on te nt
Pa d d in g
1 <?xml version = "1.0"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
4
5 <!-- Fig. 6.14: borders.html -->
6 <!-- Setting borders of an element -->
7
8 <html xmlns = "http://www.w3.org/1999/xhtml">
9 <head>
10 <title>Borders</title>
11
12
13
<style type = "text/css"> borders.html
14
15
16
body
div
(1 of 2)
{ background-color: #ccffcc }
{ text-align: center;
17 margin-bottom: 1em;
18 padding: .5em }
19
20 .thick { border-width: thick }
21
22 .medium { border-width: medium }
23
24 .thin { border-width: thin }
25
26 .groove { border-style: groove }
27
28 .inset { border-style: inset }
29
30 .outset { border-style: outset }
31
32 .red { border-color: red }
33
34 .blue { border-color: blue }
35
borders.html
36 </style>
37 </head>
38
39
40
41
<body>
(2 of 2)
<div class = "thick groove">This text has a border</div>
42 <div class = "medium groove">This text has a border</div>
43 <div class = "thin groove">This text has a border</div>
44
45 <p class = "thin red inset">A thin red line...</p>
46 <p class = "medium blue outset">
47 And a thicker blue line</p>
48
49 </body>
50 </html>
User Style Sheets
Format pages based on user preferences
User style sheets are not linked in the document
– They are set in browser's options
1 <?xml version = "1.0"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
4
5 <!-- Fig. 6.16: user_absolute.html -->
6 <!-- User styles -->
7
8 <html xmlns = "http://www.w3.org/1999/xhtml">
9 <head>
10 <title>User Styles</title>
11
12
13
User_absolute.html
<style type = "text/css">
14
15
16 </style>
(1 of 2)
.note { font-size: 9pt }
17 </head>
18
19 <body>
20
21 <p>Thanks for visiting my Web site. I hope you enjoy it.
22 </p><p class = "note">Please Note: This site will be
23 moving soon. Please check periodically for updates.</p>
24
25 </body>
26 </html>
1 /* Fig. 6.17: userstyles.css */
2 /* A user stylesheet */
3
4 body { font-size: 20pt;
5 color: yellow;
6 background-color: #000080 }
User Style Sheets
14
15
16 </style>
(1 of 2)
.note { font-size: .75em }
17 </head>
18
19 <body>
20
21 <p>Thanks for visiting my Web site. I hope you enjoy it.
22 </p><p class = "note">Please Note: This site will be
23 moving soon. Please check periodically for updates.</p>
24
25 </body>
26 </html>
User Style Sheets
227
JavaScript
• Introducing JavaScript
• It's important to understand the difference
between Java and JavaScript. Java is a full
programming
• language developed by Sun Microsystems
with formal structures, etc. JavaScript is a
scripting language
• developed by Netscape that is used to modify
web pages. Most JavaScript must be written in
228
JavaScript
• the HTML
• document between <SCRIPT> tags. You open
with a <SCRIPT> tag, write your JavaScript,
and write a
• closing </SCRIPT> tag. Sometimes, as an
attribute to script, you may add
“Language=JavaScript”
• because there are other scripting languages as
well as JavaScript that can be used in HTML.
229
JavaScript
• We’ll go
• through some examples to demonstrate the
syntax of JavaScript.
• To understand the workings of JavaScript, it is
essential to understand a few basic
programming concepts.
• JavaScript is object-oriented. An Object in
JavaScript is a resource that has specific
characteristics known
• as properties and provides several services 230
JavaScript
• known as methods and events. An example of
an object is
• document, which represents the current web
page and has properties such as location
( which stores the
• URL location of the document) and methods
such as writeln , which writes dynamically
created html text
• to the document.
231
History
JavaScript created by Netscape
JScript created by Microsoft
IE and Netscape renderings are slightly different
Standardized by European Computer Manufacturers
Association (ECMA)
http://www.ecma-international.
org/publications /standards/Ecma-262.htm
232
General Format
<!doctype ...>
<html>
<Head>
<Title> Name of web page </title>
<script type="text/javascript">
...script goes here
</script>
</head
<body>
...page body here: text, forms, tables
...more JavaScript if needed
...onload, onclick, etc. commands here
</body>
</html> 233
Characteristics
Case sensitive
Object oriented
Produces an HTML document
Dynamically typed
Standard operator precedence
Overloaded operators
Reserved words
234
Characteristics
Division with / is not integer division
Modulus (%) is not an integer operator
5 / 2 yields 2.5
5.1 / 2.1 yields 2.4285714285714284
5 % 2 yields 1
5.1 % 2.1 yields 0.8999999999999995
235
Characteristics
" and ' can be used in pairs
Scope rules for variables
Strings are very common data types
Rich set of methods available
Arrays have dynamic length
Array elements have dynamic type
Arrays are passed by reference
Array elements are passed by value
236
JavaScript Topics
code placement while loops
document.writeln do-while loops
document tags if-else
variable values in tags
window.alert
math library
user input/output
switch
parseInt and parseFloat break
arithmetic labeled break
arithmetic comparisons continue
for loops Booleans
237
JavaScript Topics
functions arrays
random numbers searching
rolling dice strings
form input substrings
form output string conversions
submit buttons markup methods
games
238
JavaScript’s Uses Include:
“Dynamic” web-pages
– What’s DHTML? (in a second)
Image manipulation
– Swapping, rollovers, slide shows, etc.
Date, time stuff (e.g. clocks, calendars)
HTML forms processing
– Verifying input; writing output to fields
Cookies
239
What’s DHTML?
Purpose: make dynamic / interactive web-pages on
the client side
Use of a collection of technologies together to do
this, including
– Markup language (HTML, XML, etc.)
– Scripting language (JavaScript, etc.)
– Presentation language (CSS etc.)
240
Other References
CS453 Virtual Lab exercises
The Web Wizard’s Guide To JavaScript, Steven
Estrella, Addison-Wesley
JavaScript for the World Wide Web, Gesing and
Schneider, Peachpit Press
http://www.w3schools.com/js/
www.javascript.com
E-books in UVa’s Safari On-line Books:
http://proquest.safaribooksonline.com/search
241
Browser Compatability
Use of:
<script type=”text/javascript"
language=”javascript" >
<!--
242
Organization of JavaScript
Create functions (non-OO style)
– Define in header
– Or load a .js file in header:
<script type="text/javascript"
language="javascript" src="mylib.js">
Functions called in <BODY>
– Often in response to events, e.g.
<input type="button"… onclick="myFunc(…);">
Global variables
243
document.writeln
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<!– Welcome to JavaScript -->
<HEAD>
<TITLE> Welcome to JavaScript </TITLE>
<SCRIPT TYPE="text/javascript">
document.writeln( "<FONT COLOR='magenta'><H1>Welcome
to ",
"JavaScript Programming!</H1></FONT>" );
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML> 244
document.write
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN">
<HTML>
<HEAD>
<TITLE> Using document.write </TITLE>
<SCRIPT TYPE="text/javascript">
document.write ( "<H1>Welcome to ");
document.writeln( "JavaScript Programming!</H1>" );
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
245
window.alert
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Using window.alert </TITLE>
<SCRIPT TYPE="text/javascript">
window.alert( "Welcome to\nJavaScript\nProgramming!" );
</SCRIPT>
</HEAD>
<BODY>
<P>Click Refresh (or Reload) to run this script again.</P>
</BODY>
</HTML>
246
User input/output
<SCRIPT TYPE="text/javascript">
var firstNumber, // first string entered by user
secondNumber, // second string entered by user
number1, // first number to add
number2, // second number to add
sum; // sum of number1 and number2
// read in first number from user as a string
firstNumber = window.prompt("Enter first integer", "0" );
// read in second number from user as a string
secondNumber = window.prompt( "Enter second integer", "0" );
// convert numbers from strings to integers
firstNumber = parseInt(firstNumber);
number2 = parseInt( secondNumber );
// add the numbers
sum = firstNumber + number2;
// display the results
document.writeln( "<H1>The sum is " + sum + "</H1>" );
247
</SCRIPT>
Functions
<SCRIPT TYPE = "text/javascript">
var input1 = window.prompt( "Enter first number", "0" );
var input2 = window.prompt( "Enter second number", "0" );
var input3 = window.prompt( "Enter third number", "0" );
var value1 = parseFloat( input1 );
var value2 = parseFloat( input2 );
var value3 = parseFloat( input3 );
var maxValue = maximum( value1, value2, value3 );
document.writeln( "First number: " + value1 +
"<BR>Second number: " + value2 +
"<BR>Third number: " + value3 +
"<BR>Maximum is: " + maxValue );
// maximum method definition (called from above)
function maximum( x, y, z ) {
return Math.max( x, Math.max( y, z ) );
}
248
</SCRIPT>
Random Numbers
<SCRIPT TYPE="text/javascript">
var value;
document.writeln( "<H1>Random Numbers</H1>" +
"<TABLE BORDER = '1' WIDTH = '50%'><TR>" );
for ( var i = 1; i <= 20; i++ ) {
value = Math.floor( 1 + Math.random() * 6 );
document.writeln( "<TD>" + value + "</TD>" );
if ( i % 5 == 0 && i != 20 )
document.writeln( "</TR><TR>" );
}
document.writeln( "</TR></TABLE>" );
</SCRIPT>
249
Roll the Die
<SCRIPT TYPE="text/javascript">
var frequency1 = 0, frequency2 = 0,
frequency3 = 0, frequency4 = 0,
frequency5 = 0, frequency6 = 0, face;
// summarize results
for ( var roll = 1; roll <= 6000; ++roll ) {
face = Math.floor( 1 + Math.random() * 6 );
switch ( face ) {
case 1: ++frequency1; break;
case 2: ++frequency2; break;
case 3: ++frequency3; break;
case 4: ++frequency4; break;
case 5: ++frequency5; break;
case 6: ++frequency6; break;
}
}
document.writeln( "<TABLE BORDER = '1' WIDTH = '50%'>" ); .....
250
Rules of Craps
First roll:
– 7 or 11 is a win
– 2, 3, or 12 is a lose
– otherwise, roll becomes your point
Subsequent rolls:
– rolling your point is a win
– 7 or 11 is a lose
– otherwise continue to roll
251
Craps
<SCRIPT TYPE="text/javascript">
// variables used to test the state of the game
var WON = 0, LOST = 1, CONTINUE_ROLLING = 2;
// other variables used in program
var firstRoll = true, // true if first roll
sumOfDice = 0, // sum of the dice
myPoint = 0, // point if no win/loss on first roll
gameStatus = CONTINUE_ROLLING; // game not over yet
252
Craps
// process one roll of the dice
function play() {
if ( firstRoll ) {
// first roll of the dice
sumOfDice = rollDice();
switch ( sumOfDice ) {
case 7: case 11:
// win on first roll
gameStatus = WON;
document.craps.point.value = ""; // clear point field
break;
case 2: case 3: case 12:
// lose on first roll
gameStatus = LOST;
document.craps.point.value = ""; // clear point field
253
break;
Craps
default:
// remember point
gameStatus = CONTINUE_ROLLING;
myPoint = sumOfDice;
document.craps.point.value = myPoint;
firstRoll = false;
}
}
else {
sumOfDice = rollDice();
if ( sumOfDice == myPoint ) gameStatus = WON;
else if ( sumOfDice == 7 ) gameStatus = LOST;
}
254
Craps
if ( gameStatus == CONTINUE_ROLLING ) window.alert ("Roll again");
else {
if ( gameStatus == WON ) {
window.alert ("Player wins. " + "Click Roll Dice to play again.");
document.craps.point.value = " ";
}
else {
window.alert ("Player loses. " + "Click Roll Dice to play again.");
document.craps.point.value = " ";
}
firstRoll = true;
}
}
255
Craps
<SCRIPT TYPE="text/javascript">
function rand1toN(N) {
return Math.floor( 1+Math.random()*N );
}
function dealcard(card) {
var rank = new Array(0,"A","2","3","4","5","6","7",
"8","9","T","J","Q","K");
var suit = new Array(0, "Spades", "Hearts", "Diamonds", "Clubs");
card[0] = rank[rand1toN(13)];
card[1] = suit[rand1toN(4)];
}
257
Poker Hand
258
Poker Hand
259
Character Processing
<SCRIPT TYPE="text/javascript">
var s = "ZEBRA";
var s2 = "AbCdEfG";
document.writeln( "<P> Character at index 0 in '"+
s + '" is " + s.charAt( 0 ) );
document.writeln( "<BR>Character code at index 0 in '" +
s + "' is " + s.charCodeAt( 0 ) + "</P>" );
document.writeln( "<P>'" + String.fromCharCode( 87, 79, 82, 68 ) +
"' contains character codes 87, 79, 82 and 68</P>" );
document.writeln( "<P>'" + s2 + "' in lowercase is '" +
s2.toLowerCase() + "'" );
document.writeln( "<BR>'" + s2 + "' in uppercase is '" +
s2.toUpperCase() + "'</P>" );
</SCRIPT>
260
Dates and Times
<SCRIPT LANGUAGE = "JavaScript">
var current = new Date();
document.writeln(current);
document.writeln( "<H1>String representations and valueOf</H1>" );
document.writeln( "toString: " + current.toString() +
"<BR>toLocaleString: " + current.toLocaleString() +
"<BR>toUTCString: " + current.toUTCString() +
"<BR>valueOf: " + current.valueOf() );
document.writeln( "<H1>Get methods for local time zone</H1>" );
document.writeln( "getDate: " + current.getDate() +
"<BR>getDay: " + current.getDay() + "<BR>getMonth: " +
current.getMonth() + "<BR>getFullYear: " + current.getFullYear() +
"<BR>getTime: " + current.getTime() + "<BR>getHours: " +
current.getHours() + "<BR>getMinutes: " + current.getMinutes() +
"<BR>getSeconds: " + current.getSeconds() + "<BR>getMilliseconds: " +
current.getMilliseconds() + "<BR>getTimezoneOffset: " +
current.getTimezoneOffset() ); 261
Dates and Times
anotherDate.setDate( 31 );
anotherDate.setMonth( 11 );
anotherDate.setFullYear( 1999 );
anotherDate.setHours( 23 );
anotherDate.setMinutes( 59 );
anotherDate.setSeconds( 59 );
document.writeln( "Modified date: " + anotherDate );
</SCRIPT> 262
Events
263
Events
264
The end