5th Sem GCA 02 B1
5th Sem GCA 02 B1
Exam. Code: WT
Web Technology
SEMESTER V
Course Co-ordinators
UNITS CONTRIBUTORS
Editorial Team
This Self Learning Material (SLM) of the Krishna Kanta Handiqui State University is
made available under a Creative Commons Attribution-Non Commercial-ShareAlike4.0 License
(International): http.//creativecommons.org/licenses/by-nc-sa/4.0.
Printed and published by Registrar on behalf of the Krishna Kanta Handiqui State Open University.
The university acknowledges with thanks the financial support provided by the
Distance Education Bureau, UGC for the preparation of this study material.
BACHELOR OF COMPUTER APPLICATION
Web Technology
Block-1
CONTENTS
Pages
UNIT 1: Basics of Internet and Web 7-25
The Basics of Internet, World Wide Web, Web Page, Home Page, Web Site,
Static, Dynamic and Active Web Page, Overview of Protocols– Simple Mail
Transfer Protocol, Gopher, Telnet, Emails, FTP, Hyper Text Transfer Protocol,
Client Server Computing Concepts, MIME, Web Surfing
This course is on Web Technology. Web Technology includes Web development and designing.
Web design is about how to make the website unique and user friendly. The methods by which computers
communicate with each other through the use of markup languages and multimedia packages is known
as Web technology. The course emphasises the fundamentals of Web page development and prepares
the learners to build real-world, Web-based applications and to use a wide variety of Web development
tools effectively and efficiently.
Block 1 describes Internet and Web. Learners are introduced to the concepts of Internet Protocols
commonly used in Web applications, Hypertext Markup Language and various features of
CSS, Dynamic HTML. Markup languages are the languages in which the web is written. Learners
will be able to design web pages including pictures, links, table, lists, frames and form after
going through this block.
Block 2 starts with JavaScript. It describe the various concepts of web technologies, namely, ML, AJAX,
XML, server-side scripting PHP.
BLOCK INTRODUCTION
This is the first block of the course Web Technology. Various concepts associated with World
Wide Web and Internet are discussed in this block. It has also described the concept of web server and
web client. Different tags of Hypertext Markup Language, features of CSS and Dynamic HTML are other
topics being discussed in this block. Learners will be able to design attactive web pages learning the
features of HTML, CSS and Dynamics HTML .
Unit 1 is an introductory unit on Internet and Web. Concept of Web page, Home page, Website and
various important protocols like SMTP, Telnet, FTP, HTTP etc.are introduced in this unit.
Unit 2 is on Web Client. This unit discusses some important web browsers, client-side scripting
language and also Active X control and Plug-ins.
Unit 3 is on Web server. It describes the web server architecture in the beginning. It also introduces
Image maps, CGI and ODBC at the end.
Unit 4 introduces HTML and the various tags of HTML with their attributes. This unit is intended to
give the learner the ability to create HTML documents.
Unit 5 describes HTML lists and Tables. With this unit the learners will be able to create tables in a
web page and add list of items with the use of different HTML lists and attributes.
Unit 6 is on HTML frames and forms. This unit describes how to devide the web page into frames so
that one part can be kept fixed and the other part is kept movable as per user requirement.
Learners will also be able to design HTML forms and take users input in such forms.
Unit 7 introduces Casecading Style Sheet. Inline Style Sheet, Embedded Style Sheet, External Style
Sheet etc. are described in this unit.
Unit 8 is on Dynamic HTML. Different features of DHTML , DOM, CSS positioning etc. are discussed
in this unit.
Each unit of this block includes some along-side boxes to help you know some of the difficult,
unseen terms. Some “EXERCISES” have been included to help you apply your own thoughts. You may
find some boxes marked with: “LET US KNOW”. These boxes will provide you with some additional
interesting and relevant information. Again, you will get “CHECK YOUR PROGRESS” questions. These
have been designed for you to self-check your progress of study. It will be helpful for you if you solve the
problems put in these boxes immediately after you go through the sections of the units and then match
your answers with “ANSWERS TO CHECK YOUR PROGRESS” given at the end of each unit.
6 Web Technology
UNIT 1: BASICS OF INTERNET AND WEB
UNIT STRUCTURE
1.1 Learning Objectives
1.2 Introduction
1.3 Basics of Internet
1.3.1 Usage of Internet
1.3.2 Advantages of Internet
1.3.3 Disadvantages and Limitations of Internet
1.4 World Wide Web
1.4.1 Web Page
1.4.2 Home Page
1.4.3 Website
1.4.4 Different Types of Web Documents
1.4.5 Advantages and Disadvantages
1.5 Protocols
1.6 Client Server Computing Techniques
1.7 MIME
1.8 Web Surfing
1.9 Let Us Sum Up
1.10 Further Reading
1.11 Answers to Check Your Progress
1.12 Model Questions
1.2 INTRODUCTION
This is the first unit of the course. Here, we will discuss the basics of
Internet and Web. Internet is a network of computers linking many different
types of computers all over the world. It primarily consists of billions of
interconnected Web Pages and thus creating World Wide Web. In 21 st
century, Internet facilities dominate all kinds of works such as household
works, personal works and mainly official works. For internet only, people
are getting connected across the world and contributing their innovative
works to this world.
Different terminologies associated with Internet and Web as well as
various protocols will be described in this unit.
8 Web Technology
Basics of Internet and Web Unit 1
Web Technology 9
Unit 1 Basics of Internet and Web
1.4.3 Website
Web Technology 13
Unit 1 Basics of Internet and Web
1.5 PROTOCOLS
1.7 MIME
The term “surfing” was first coined by Mark McCahill. In the World
Wide Web, surfing means to move from one Webpage to another, usually
in an undirected manner. When surfing, the user typically visits pages based
on what interests him/her at the moment.
Surfing is an activity that started with the advent of the World Wide
Web. With hypertext links, users can go not only from one part of a document
to another, but also from one document to another, including those located
in remote sites. Surfing is a favorite pastime for millions of people around
the world who have access to the Internet. Many users are hooked on it,
spending countless hours doing casual searches or other online activities.
Some of the advantages and disadvantages of surfing are as follows:
Web Technology 19
Unit 1 Basics of Internet and Web
Advantages:
z Mostly information on various subjects are available.
z Search engines are powerful.
z Ability to do research from your home versus research libraries.
z Message boards where people can discuss ideas on any topic. Ability
to get wide range of opinions. People can find others that have a
similar interest in whatever they are interested in.
z The internet provides the ability of emails. Free mail service to anyone
in the country.
z Platform for products like SKYPE, which allow for holding a video
conference with anyone in the world who also has access.
z Many Connections between people from worldwide can be made
via social networking.
z Things such as Yahoo Answers and other sites where kids can have
readily available help for homework.
z News, of all kinds is available almost instantaneously. Commentary,
on that news, from every conceivable viewpoint is also available.
Disadvantages:
z There is a lot of wrong information on the internet. Anyone can post
anything, all sources are not reliable.
z There are predators that hang out on the internet waiting to get
unsuspecting people in dangerous situations.
z Some people are getting addicted to the internet and thus causing
problems with their family and career.
z Many Multimedia contents may be harmful for students.
z Easy to waste a lot of time on the internet. You can start surfing, and
then realize far more time has passed than we realized.
z There are a lot of unscrupulous businesses that have sprung up on
the internet to take advantage of people.
z Hackers can create viruses that can get into your personal computer
and ruin valuable data, They can use the internet for identity theft.
20 Web Technology
Basics of Internet and Web Unit 1
z The internet helps us achieve this in several different ways. For the
students and educational purposes the internet is widely used to gather
information so as to do the research or add to the knowledge of various
subjects. Even the business professionals and the professionals like
doctors, access the internet to filter the necessary information for their
use.
z The World Wide Web (WWW) is the universe of network-accessible
information in Internet sites that can be accessed by using a hypertext
interface. Hypertext interface means online pages which are formatted
in markup languages like HTML, XML etc. and accessed via HTTP.
z A web page is a document commonly written in Markup Languages
like HTML that is accessible using an Internet Browser with proper
internet connectivity.
z The homepage or home page is the name of the main page of any
website where visitors can find hyperlinks to other pages on the site.
z A Web site is a related collection of World Wide Web (WWW) files that
includes a beginning file called a homepage.
z Protocols are some of rules and guidelines needed to be followed while
communicating between systems.
z The client server computing works with a system of request and
response. The client sends a request to the server and the server
responds with the desired information.
z MIME is an extension of the original Internet email protocol that that
helps extend the limited capabilities of email by allowing insertion of
images, sounds and text in a message.
z Web surfing means to move from one Web page to another.
22 Web Technology
Basics of Internet and Web Unit 1
24 Web Technology
Basics of Internet and Web Unit 1
Web Technology 25
UNIT 2: WEB CLIENT
UNIT STRUCTURE
2.2 INTRODUCTION
In the previous unit we have learnt about the basics of Internet and
Web, and the various terminologies associated with these two technologies.
We have also learnt few important protocols and concepts of client-server
computing.
In this unit we will discuss Web Client. A web client is an application
that communicates with a web server, using Hypertext Transfer Protocol
(HTTP). HTTP is the protocol behind the World Wide Web. With every web
26 Web Technology
Web Client Unit 2
during the early 1990’s and in a browser war with Microsoft Internet
Explorer. The popularity and use of Netscape declined in the late
1990’s, which led to the open source Mozilla project.
z Mozilla Firefox: The Firefox web browser was first released in beta
on September 23, 2002, as the “Mozilla Browser,” although it was
internally code-named “Phoenix.” Firefox 1.0 was officially released
on November 9, 2004. Firefox is a Web browser that is smaller, faster,
and in some ways more secure than the Mozilla browser from which
much of its code was originally derived. Firefox included almost all
the features offered by other browsers at that time, as well as a
number of new features, including a bookmarks toolbar and tabbed
browsing. Firefox’s user interface was also easily customizable with
the help of extensions, such as auto fill and stock tracker.
z Internet Explorer: A Web browser that made its debut in 1995 as
Microsoft’s response to Netscape, one of the first graphical-based
Web browsers and, at the time, the dominant browser in use with
control of over 90 percent of the market. It is included with the Windows
Operating System. Often abbreviated as IE or MSIE, Microsoft
Internet Explorer is an Internet browser that allows users to utilize
Internet Explorer to listen to and watch streaming content, access
online banking and make purchases over the Internet, and much more.
As with most modern browsers, Internet Explorer supports Java,
JavaScript, ActiveX, RSS, CSS and Ajax, while also offering features
like tabbed browsing, private browsing, and built-in malware and
phishing protection.
z Google Chrome: It is one of the most widely used web browser in
the world today. Google Chrome is created by Google and based on
the open source Chromium project. Google released Chrome in
2008 and issues several updates a year. It is available for operating
systems like Windows, Linux and Mac OS etc. Each open website
runs as its own process, which helps prevent malicious code on one
page from affecting others (or the computer operating system at large).
The browser also supports Web standards such as HTML5 and
cascading style sheets (CSS), Java, JavaScript, ActiveX and Ajax etc.
28 Web Technology
Web Client Unit 2
2.4.1 VBScript
<html>
<head>
<title>My First VBScript Code!!!</title>
</head>
<body>
<script type=”text/vbscript”>
document.write(“Yes!!! I have started learning
VBScript.”)
</script></body></html>
30 Web Technology
Web Client Unit 2
2.4.2 JavaScript
<script ...>
JavaScript code
</script>
<html>
<body>
<script language = “javascript” type =
“text/javascript”>
document.write(“Hello World”)
</script>
</body>
</html>
2.5 ACTIVE X
Web Technology 33
Unit 2 Web Client
2.6 Plug-ins
Web Technology 35
Unit 2 Web Client
36 Web Technology
Web Client Unit 2
is smaller, faster, and in some ways more secure than the Mozilla
browser from which much of its code was originally derived.
Firefox included almost all the features offered by other browsers
at that time, as well as a number of new features, including a
bookmarks toolbar and tabbed browsing. Firefox’s user interface
was also easily customizable with the help of extensions, such
as auto fill and stock tracker.
ii) Internet Explorer: A Web browser that made its debut in 1995
as Microsoft’s response to Netscape, one of the first graphical-
based Web browsers and, at the time, the dominant browser in
use with control of over 90 percent of the market. It is included
with the Windows Operating System. Often abbreviated as IE
or MSIE, Microsoft Internet Explorer is an Internet browser
that allows users to utilize Internet Explorer to listen to and watch
streaming content, access online banking and make purchases
over the Internet, and much more. As with most modern
browsers, Internet Explorer supports Java, JavaScript, ActiveX,
RSS, CSS and Ajax, while also offering features like tabbed
browsing, private browsing, and built-in malware and phishing
protection.
iii) Google Chrome: It is one of the most widely used web browser
in the world. Google Chrome is created by Google and based
on the open source Chromium project. Google released Chrome
in 2008 and issues several updates a year. It is available for
operating systems like Windows, Linux and Mac OS etc.. Each
open website runs as its own process, which helps prevent
malicious code on one page from affecting others (or the
computer operating system at large). The browser also supports
Web standards such as HTML5 and cascading style sheets
(CSS), Java, Javascript, ActiveX and Ajax etc.
Ans to Q. No. 2: Client Side Scripting is utilized when the client’s (user’s)
browser has all the code and the page is modified on the basis of
the client’s (user’s) information. The Web Browser executes the client
Web Technology 37
Unit 2 Web Client
38 Web Technology
Web Client Unit 2
Web Technology 39
UNIT 3: WEB SERVER
UNIT STRUCTURE
3.1 Learning Objectives
3.2 Introduction
3.3 Web Server and its Architecture
3.3.1 Apache Web Server
3.3.2 IIS Web Browser
3.3.3 Nginx Web Browser
3.3.4 Light Speed Web Browser
3.4 Image Map
3.4.1 Client side and Sever Side Image Map
3.4.2 Client Side Image Map
3.4.3 Server Side Image Map
3.5 Common Gateway Interface
3.6 Application Program Interface
3.7 Web Database Connectivity
3.7.1 Open Database Connectivity
3.7.2 Working
3.8 Proxy Server
3.9 Let Us Sum Up
3.10 Further Reading
3.11 Answers to Check Your Progress
3.12 Model Questions
3.2 INTRODUCTION
Web Technology 41
Unit 3 Web Server
An Image Map on the World Wide Web permits the web document
writer to include in its document the ability for a viewer to “click” on a portion
of a GIF or JPEG (or any other image) file. There are three components in
a Web page image map:
Web Technology 43
Unit 3 Web Server
44 Web Technology
Web Server Unit 3
<a href=”/cgi-bin/imagemap/user_dir/image.map”>
<img src=”/user_dir/image.gif”>
</a>
Web Technology 45
Unit 3 Web Server
3.7.2 Working
50 Web Technology
Web Server Unit 3
Web Technology 51
Unit 3 Web Server
z Web server is used to host the web sites but there exist other web servers
also such as gaming, storage, FTP, email etc. Web server is a program
52 Web Technology
Web Server Unit 3
that uses HTTP to serve files that create web pages to users in response
to their requests, which is sent by their computers HTTP connection.
z Web Server Architecture follows the following two approaches:
Concurrent Approach, Single-Process-Event-Driven Approach.
z An Image Map on the WWW permits the web document writer to include
in its document the ability for a viewer to “click” on a portion of a GIF or
JPEG (or any other image) file.
z CGI is the abbreviation of Common Gateway Interface. It is a specification
for transferring information between a World Wide Web server and a
CGI program. A CGI program is any program designed to accept and
return data that conforms to the CGI specification. The program could be
written in any programming language, including C, Perl, Java, or Visual
Basic.
z APIs are a set of tools that allow software developers to create software
applications. Basically, an API specifies how software components should
interact.
z A Web database is a database application designed to be managed
and accessed through the Internet. The content of any website for a
business or organization comprises data, including text, images, media
and numerical values. Using a database to store this data is an efficient
approach for many sites.
z Open Database Connectivity or ODBC is an application programming
interface (API) that lets software connect with database management
systems while remaining independent of them.
z Proxy server is a computer that sits between a client computer and the
Internet, and provides indirect network services to a client. It may reside
on the user’s local computer, or at various points between the user’s
computer and destination servers on the Internet.
z Improving performance
z Translation
z Accessing services anonymously
z Security
Ans. to Q. No. 5: ii) Web Server is a computer where the web content is
stored and Web Browser request those content.
Ans. to Q. No. 6: Web Server Architecture follows the following two
approaches:
1) Concurrent Approach
2) Single-Process-Event-Driven Approach
Ans. to Q. No. 7: Google Maps is a Web-based service that provides
detailed information about geographical regions and sites around
the world. In addition to conventional road maps, Google Maps offers
aerial and satellite views of many places. In some cities, Google Maps
offers street views comprising photographs taken from vehicles.
56 Web Technology
UNIT 4: INTRODUCTION TO HTML
UNIT STRUCTURE
4.1 Learning Objectives
4.2 Introduction
4.3 Basics of HTML
4.3.1 HTML Tags
4.3.2 HTML Editor
4.4 Document Structure Tags
4.5 Formatting Tags
4.6 Hypertext, Hyperlink and Hypermedia
4.7 Anchor and URL
4.8 Inserting Images
4.9 Let Us Sum Up
4.10 Further Reading
4.11 Answers to Check Your Progress
4.12 Model Questions
4.2 INTRODUCTION
In this unit we will learn how to create simple web pages using HTML
tags. Here, we will discuss mainly formatting tags, image tags and tags
related with linking different web pages.
author and their profile etc. It is also a container tag. It may contain
other tags like: <TITLE>, <LINK>, <META> etc.
Syntax:
<HEAD>
Header section documents and tags only
</HEAD>
iii) <TITLE> tags: This tag is used for creating the title of the web page
document. It is a container tag.
Syntax:
<TITLE> Title of the web page document. </ TITLE >
iv) <BODY> tags: It is used for creating the body section of the HTML
document. This section contains the actual web page document,
which is visible to the user through a web browser. Major portion of
the tags are belonging to this section.
Syntax:
Standard English
Color: The 16 <BODY Bgcolor=‘‘color” Text=‘‘text-color”
standard colors are: Link=‘‘unvisited-link-color” Alink=‘‘active-
Black, White, Aqua, link-color” Vlink=‘‘visited-link-color”>
Silver, Gray, Maroon,
… Body section documents and tags.
Red, Purple, Fuschia,
</BODY>
Green, Lime, Olive,
Yellow, Navy, Blue and Attributes: Bgcolor: Here we can set the background color, which
Teal. is either 16 Standard English Color or an RGB hexadecimal triplet e.g.,
RGB hexadecimal Color=‘‘#FF44AA”
triplet: It is a Text: Here we can set the color of the entire document.
combination of three
Link: It sets the color of unvisited hyperlinks.
colors: Red, Green
and Blue. It has six
Alink: It sets the color of active hyperlinks.
digits, every Vlink: It sets the color of visited hyperlinks.
continuous two digit Example:
represent one color. <HTML>
Each digit is
<BODY Bgcolor=‘‘Yellow” Text=‘‘Blue”>
represented by a
Krishna Kanta Handique State Open University<BR>
hexadecimal number.
So, it takes value Assam<BR>
between “#000000” </BODY>
and “#FFFFFF”. </HTML>
60 Web Technology
Introduction to HTML Unit 4
This will change the background of the web page to yellow. The text
‘‘Krishna Kanta Handique State Open University’’ will be in blue colour.
Syntax:
<Small> … Text in smaller size … </ Small >
v) <B> tag: It is a container tag. Using this tag we can change the
enclosed text to be bold.
Syntax:
<B> …Boldface text goes here... </B>
vi) <I> tag: It is a container tag. Using this tag we can change the enclosed
text to be italics.
Syntax:
<I> …Italic text goes here... </I>
vii) <U> tag: It is a container tag. Using this tag we can change the
enclosed text to be underlined.
Syntax:
<U> …Underlined text goes here... </U>
viii) <S> or <Strike>tag: It is a container tag. Using this tag we can put
a strikethrough character over the enclosed text.
Syntax:
<S> … Strikethrough text goes here... </S> (or)
<Strike> … Strikethrough text goes here... </ Strike>
ix) <Sub> tag: It is a container tag. Using this tag we can make the
enclosed text as subscript one.
Syntax :
<Sub> … subscript text goes here... </Sub>
x) <Sup> tag: It is a container tag. Using this tag we can make the
enclosed text as superscript one.
Syntax:
<Sup> … superscript text goes here... </Sup>
xi) <TT> tag: It is a container tag. Using this tag we can obtain a fixed
width font, which is equivalent to typewriter font.
Syntax:
<TT> … Text with typewriter font goes here... </TT>
xii) <DFN> tag: It is a container tag. Using this tag we can define the
instance of a term. Some browsers display it in italic text.
62 Web Technology
Introduction to HTML Unit 4
Syntax:
<DFN> … Term to be defined goes here... </DFN>
xiii) <EM> tag: It is a container tag. Using this tag we can obtain
emphasized text against the enclosed text. Most of the browsers
display it in italic text.
Syntax:
<EM> … Emphasized text goes here... </EM>
xiv) <STRONG> tag: It is a container tag. Using this tag we can obtain
strongly emphasized text against the enclosed text. Most of the
browsers display it in boldface text.
Syntax:
<STRONG> …Strongly emphasized text goes here...
</STRONG>
xv) <BR> tag: It is a standalone tag. It is used to insert a line break in
the document. Even if we write the text in different line while designing
the documents, browser will not display them in different lines. i.e.
Browser do not understand carriage return.
Syntax:
<BR>
xvi) <CENTER> tag: It is a container tag. Using this tag we can align the
page contents into centre position.
Syntax:
<CENTER> … Page content with center alignment...
</CENTER>
xvii) <DIV> tag: It is a container tag. It contains division of document,
which requires special alignment.
Syntax:
<DIV Align= ‘‘left| right| center| justify”>
… Text to be aligned...
</DIV>
xviii) <HR> tag: It is a standalone tag. It is used to insert a horizontal line
on the page.
Web Technology 63
Unit 4 Introduction to HTML
Syntax:
<HR Align= ‘‘left|right|center” Noshade Size=
‘‘thickness” Width=‘‘percentage of screen or no.
of pixels”>
Attributes:
Align: default is center.
Noshade: It suppresses the shading effect.
Size: It indicates thickness of the line in pixels.
Width: Here we can set the width of the line in two ways- percentage
of the screen or number of pixels.
xix) <H1>- <H6> tag: These are container tags. Using these six tags we
can set six different levels of heading. <H1> creates the largest
possible heading whereas <H6> creates the smallest possible heading.
Each heading will be of boldface text with little extra line spacing.
Syntax:
<Hn Align= ‘‘left|right|center|justify”>
Level n heading
</Hn>
Where n may be any digit between 1 and 6.
xx) <P> tag: It is a container tag. Using this tag we can denote a
paragraph. Multiple uses of <P> tags make no difference. i.e.,
Browser ignores the use of multiple tags.
Syntax:
<P Align=”left|right|center|justify”>
Paragraph text
</P>
xxi) <PRE> tag: It is a container tag. It is used to display pre-formatted
text. i.e., The enclosed text will be displayed as it is.
Syntax:
<PRE Width= ‘‘Width of the widest line”> Preformatted
text </PRE>
xxii) <SPAN> tag: It is a container tag. It is used to apply some of the
style information.
64 Web Technology
Introduction to HTML Unit 4
Syntax:
<SPAN Style=‘‘style information” Align=‘‘left|right|
center| justify”>
Text on which style is to be applied.
</SPAN>
The <a> tag is supported in all major browsers like Internet Explorer,
Mozilla Firefox, Google Chrome, Opera and Safari.
The <a> tag supports the following standard attributes:
access key Specified a keyboard shortcut to access an element.
class Specifies a classname for an element.
dir Specifies the text direction for the content in an element.
id Specifies a unique id for an element.
lang Specifies a language code for the content in an element.
style Specifies an inline style for an element.
tabindex Specifies the taborder of an element.
title Specifies extra information about an element.
Example:
<html>
<head>
<title>Anchor</title>
</head>
<body>
<a href=‘‘http://www.kkhsou.org/”>Go</a>
</body>
</html>
The above code gives the following output in Mozilla Firefox:
Clicking on the link “Go” will direct us to the page which is defined
by the href attribute of the <a> tag. Since the value of the href attribute is
68 Web Technology
Introduction to HTML Unit 4
70 Web Technology
Introduction to HTML Unit 4
Web Technology 71
Unit 4 Introduction to HTML
z HTML, which stands for Hyper Text Markup Language, is the Universal
language on which the web documents(pages) are written (e.g.,
especially pages on the World Wide Web).
z In HTML, a tag tells the browser what to do. When you write an HTML
page, you enter tags for many reasons– to change the appearance of
text, to show a graphic, or to make a link to another page. HTML tags
are divided into two types. Container tags and Standalone tags or empty
tags.
z The extension of the HTML file is written as .html or .htm .
z A web page created in HTML consists of three distinct sections-
Comment section, Header section, and Body section.
z Formatting tags are used to change the typographic formatting of a
page.
z Hypermedia is a superset of hypertext that simply combines hypertext
and multimedia.
z In HTML, an anchor can be either the origin or the target (destination)
end of a hyperlink.
z A URL specifies as to where an identified resource is available and the
mechanism for retrieving it.
z <img> tag is used to insert images in a web page.
Ans. to Q. No. 1: i) font face; ii) bgcolor; iii) bold; iv) standalone; v) largest,
smallest
Ans. to Q. No. 2: No,there are single HTML tags that do not need a closing
tag. Examples are <img> tag and <br>tag.
Ans. to Q. No. 3: i) hyperlinks; ii) anchor; iii) two; iv) resource; v) relative
Ans. to Q. No. 4: i) false; ii) true; iii) false; iv) true; v) true; vi) false
Web Technology 73
UNIT 5: HTML LISTS AND TABLES
UNIT STRUCTURE
5.1 Learning Objectives
5.2 Introduction
5.3 HTML List
5.4 HTML Table
5.5 Let Us Sum Up
5.6 Further Reading
5.7 Answers to Check Your Progress
5.8 Model Questions
5.2 INTRODUCTION
In the previous unit we have learnt abount the basic HTML tags and
formatting tags. We have also learnt to insert images in a HTML document.
In this unit we will mainly discuss how to create HTML list and tables
in a web page. We will learn to add various attributes associated with HTML
list ans tables.
The type attribute of the <ol> tag, defines the type of the list item
marker:
Type Description
type="1" The list items will be numbered with numbers (default)
type="A" The list items will be numbered with uppercase letters
type="a" The list items will be numbered with lowercase letters
type="I" The list items will be numbered with uppercase roman
numbers
type="i" The list items will be numbered with lowercase roman
numbers
For example,
<ol type="a">
<li>Water</li>
<li>Milk</li>
<li>Tea</li>
</ol>
The above code will give the output as:
a) Water
b) Milk
c) Tea
Similarly, if we use <ol type="i"> in the above code, then the output will
look like:
i) Water
ii) Milk
iii) Tea
The start Attribute: We can use start attribute for <ol> tag to specify
the starting point of numbering we need. Following are the possible
options:
<ol type = "1" start = "3"> – Numerals starts with 3.
<ol type = "i" start = "4"> – Numerals starts with iv.
<ol type = "a" start = "3"> – Letters starts with c.
<ol type = "A" start = "3"> – Letters starts with C.
76 Web Technology
HTML Lists and Tables Unit 5
</li>
<li>Milk</li>
</ul>
The output will be like this:
¾ Coffee
¾ Tea
Black tea
Green tea
¾ Milk
80 Web Technology
HTML Lists and Tables Unit 5
Attribute Description
align Spefifies the alignment for the table.
bgcolor Specifies the background color of the table.
border Specifies the thickness of the outermost table border.
background Specifies a background image for the entire table.
bordercolor Specifies the border color of the table.
cellspacing Specifies the amount of space between table cells.
(default is 2)
cellpadding Specifies the amount of space between the contents of
the cell and the cell wall. (default is 1)
Web Technology 81
Unit 5 HTML Lists and Tables
Example 5.3:
<table border="1" celpadding="5">
<tr><th colspan="2">Production</th>
</tr>
<tr><td>Kaberi Sarma</td>
<td>38000</td>
</tr>
<tr><td>Gautam Baruah</td>
<td>43000</td>
</tr>
<tr><td>Dipankar Das </td>
<td>45000</td>
</tr>
<tr><th colspan="2">Sales</th>
</tr>
<tr><td>Rajib Saikia</td>
<td>38000</td></tr>
<tr><td>Meghali Dutta</td>
<td>18000</td>
</tr>
<tr><td>Jumi Saikia</td>
<td>26000</td>
</tr>
</table>
The code above uses the colspan attribute to display the following
table:
Production Sales
82 Web Technology
HTML Lists and Tables Unit 5
Figure 5.4: Use of rowspan in the cells containing Production and Sales
Example 5.5:
<html>
<head>
<title>Table</title>
</head>
<body>
<table align="left" bgcolor="yellow" border="5"
cellpadding="4" cellspacing="4" bordercolor="blue">
<tr>
<td colspan="2">Chocolate</td>
<td rowspan="2">Biscuit</td>
<td rowspan="2">Cake</td>
<td rowspan="2">Pastry</td>
</tr>
<tr>
<td>Milk</td>
<td>Wafer</td>
</tr>
<tr>
<td>Cola</td>
<td>Pepsi</td>
<td>Thumbs-up</td>
<td>Sprite</td>
<td>Fruit Juice</td>
</tr>
</table>
</body>
</html>
The above code gives the following output in Mozilla Firefox:
Milk Wafer
MCA
PG
M.Sc.IT
z The <tr> element defines a table row, the <th> element defines a table
header, and the <td> element defines a table cell.
z The "align", "bgcolor", "border", "cellpadding", "cellspacing", "width" etc.
are some of the attributes of table.
z Cellpadding specifies the space between the cell wall and the cell content.
z Cellspacing specifies the space between cells.
z The rowspan attribute specifies the number of rows a cell should span.
z The colspan attribute defines the number of columns a cell should span.
<tr>
<td bgcolor = "lime" height =100> M.ScIT</td>
</tr>
</table>
</body>
</html>
Q.1: How are the HTML lists created? What are the different categories
of HTML list?
Q.2: What is a definition list? What are the tags associated with HTML
definition list?
Q.3: How is an ordered and unordered list created? Write the HTML code
to create the following list:
<ul>
<li>MCA</li>
<li>M.Sc IT</li>
<li>PGDCA</li>
</ul>
Q.4: Write the HTML codes to create a HTML table with 6 rows and 5
columns. The table should contain marks of 5 students in three
different subjects, roll number and total marks.
Q.5: What are rowspan and colspan? Explain with an example each.
Q.6: Write the use of cellpadding and cellspacing.
Q.7: Why do we use HTML tables?
Q.8: Write the HTML code to add colour to a particular table cell.
Q.9: Can we create an ordered list inside an unordered list? Explain.
Q.10: What are definition lists? How are they used? Give an example.
Web Technology 87
UNIT 6: HTML FRAMES AND FORMS
UNIT STRUCTURE
6.1 Learning Objectives
6.2 Introduction
6.3 HTML Frames
6.4 HTML Forms
6.5 Let Us Sum Up
6.6 Further Reading
6.7 Answers to Check Your Progress
6.8 Model Questions
6.2 INTRODUCTION
web page. A few frame tags are used to create a framed layout. Let us
discuss the most important <frameset> and <frame> tag with their attributes.
<FRAMESET> tag: It is a container tag. Using this tag we can divide
the browser window into frames. It does the job in two ways: it divides the
window either horizontally or vertically.
Syntax:
<FRAMESET Rows=‘‘row size” Cols=‘‘column size”>
… Frame tags
</FRAMESET>
Attribute of FRAMESET tag: Though it has two attributes rows
and cdumns (cols), we can use only one at a time.
Rows: It divides the browser window horizontally. Here we need to
specify the size of individual fragments in pixel, in percentage of browser’s
window or an asterisk mark (i.e., *). Asterisk mark is used to indicate the
remaining horizontal portion.
Column: It divides the browser window vertically. Here also we need
to specify the size of individual fragments in pixel, in percentage of browser’s
window or an asterisk mark (i.e., *). Asterisk mark is used to indicate the
remaining vertical portion.
<FRAME> tag: It is a standalone tag. Using this tag we can place
contents into a frame.
Syntax:
<FRAME src=‘‘URL of document” Name=‘‘frame name”
Frameborder=‘‘0|1’’ Marginwidth=‘‘width in pixel”
Marginheight=‘‘height in pixel” NORESIZE
Scrolling=‘‘yes|no|auto”>
Attribute:
src=Here we need to specify the URL of the document to be placed.
Name=Name of frame can be specified here.
Frameborder=It is either 0 to indicate no border or 1 to turn on the
frame border.
Marginwidth=It specifies the size of left margin in pixel.
Marginheight= It specifies the size of top margin in pixel.
Web Technology 89
Unit 6 HTML Frames and Forms
NORESIZE: If we use this option the user will not be able to drag
and drop the frame border.
Scrolling=It can be yes, no or auto
For example, let us consider the following example with two columns.
The first column is set to 25% of the width of the browser window. The
second column is set to 75% of the width of the browser window. Suppose,
we have created two HTML document ‘‘frame_a.htm’’ and ‘‘frame_b.htm’’.
The HTML document “frame_a.htm” is put into the first column, and the
HTML document “frame_b.htm” is put into the second column:
Example 6.1:
<html>
<frameset cols=‘‘25%,75%”>
<frame src=‘‘frame_a.htm”>
<frame src=‘‘frame_b.htm”>
</frameset>
</html>
The HTML code for frame_a.htm and frame_b.htm are as follows:
<html> <html>
<head> <head>
<title>Frame_a</title> <title>Frame_b</title>
</head> </head>
<body> <body>
This is frame_a This is frame_b
</body> </body>
</html> </html>
The code in Example 6.1 gives the following output in Mozilla Firefox:
The frameset column size value can also be set in pixels (cols=
‘‘200,500’’), and one of the columns can be set to use the remaining space
(cols=‘‘25%,*”).
The IFrame tag: The <iframe> tag defines an inline frame that
contains another document. Unlike frames created by using the <frameset>
and <frame> tags, the <iframe> tag creates a frame that sits in the middle
of a regular non-framed web page. <iframe> works like <img>, only instead
of putting a picture on the page, it puts another web page. The <iframe> tag
is supported by all major browsers.
To deal with browsers that do not understand iframes, we place the
text that we want between the opening <iframe> tag and the closing </iframe>
tag.
An inline frame is marked up as follows:
<iframe src =‘‘html_intro.php” width=‘‘100%” height=‘‘00">
<p>Your browser does not support iframes.</p>
</iframe>
The <iframe> tag supports the following standard attributes:
Attribute Description:
class Specifies a classname for an element
Id Specifies a unique id for an element
style Specifies an inline style for an element
title Specifies extra information about an element
Example 6.2:
<html>
<head>
<title>Iframe</title>
</head>
<body>
<iframe src=‘‘KKHSOU.htm” width=‘‘30%” height=‘‘200">
</iframe>
<p>Some older browsers don’t support iframes.</p>
<p>If they don’t, the iframe will not be visible.</p>
</body>
</html>
Web Technology 91
Unit 6 HTML Frames and Forms
The Noframe tag: The <noframes> tag is used for browsers that
do not handle frames. The noframes element can contain all the elements
that are found inside the body element of a normal HTML page. This element
is most used to link to a non-frameset version of the web site or to display
a message to the users that frames are required. The noframes element
goes inside the frameset element.This tag is supported by all major browsers.
Example 6.3:
<html>
<frameset cols=‘‘25%,50%,25%”>
<frame src=‘‘frame_a.htm”>
<frame src=‘‘frame_b.htm”>
<frame src=‘‘frame_c.htm”>
<noframes>
92 Web Technology
HTML Frames and Forms Unit 6
tag is specified with the type attribute. An input element can be of type text
field, checkbox, password, radio button, submit button, and more. The most
common input types are described below:
Text Fields: Text fields are used when we want the user to type
letters, numbers, etc. in a form.
<input type=‘‘text” /> defines a one-line input field that a user can
enter text into. The syntax is as follows:
<form>
First name: <input type=‘‘text” name=‘‘firstname”
/><br />
Last name: <input type=‘‘text” name=‘‘lastname” />
</form>
First name:
Last name:
<form>
<input type=‘‘radio” name=‘‘sex” value=‘‘male”
/> Male<br />
<input type=‘‘radio” name=‘‘sex” value=‘‘female”
/> Female
</form>
<form>
<input type=‘‘checkbox” name=‘‘vehicle” value=‘‘Bike” />
I have a bike<br />
<input type=‘‘checkbox” name=‘‘vehicle” value=‘‘Car” />
I have a car
</form>
Username: Submit
Password Field:
<input type=‘‘password” /> defines a password field:
<form>
Password: <input type=”password” name=”pwd” />
</form>
The output in a browser window will be like this:
Password:
The characters in a password field are masked (shown as asterisks
or circles).
Text Area: When the single line approach of a regular text input field
is not enough for long lines of text, the textarea input field is used which
Web Technology 95
Unit 6 HTML Frames and Forms
allows ample space to type-in the text. The <textarea> tag must be used
with a closing </textarea> tag, and the text placed between them will be the
default text inside the text field.
Syntax:
Example 6.4:
<select name=‘‘selectionlist” size=‘‘5’’
multiple=‘‘multiple”>
<option>First</option>
<option>Second</option>
<option>Third</option>
<option selected=‘‘selected”>Fourth</option>
<option>Fifth</option>
<option>Sixth</option>
<option>Seventh</option>
<option>Eighth</option>
<option>Ninth</option>
<option>Tenth</option>
</select>
Action attribute and the Submit Button: When the user clicks on
the “Submit” button, the content of the form is sent to the server. The form’s
action attribute defines the name of the file to which the content is to be
sent. The file defined in the action attribute usually does something with
the received input. A “Reset” button at the end allows the user to completely
reset/ empty all the input fields, so that the user can re-enter all the values.
Example 6.5: The following code demonstrates the use of all the
above form elements.
<html>
<head>
<title>Forms</title>
</head>
<body>
<form action=‘‘process.php” method=‘‘post”>
Username: <input type=‘‘text” name=‘‘user”><br><br>
Password: <input type=‘‘password”
name=‘‘password”><br><br>
Name: <input type=‘‘text” name=‘‘name1’’><br><br>
Gender: <input type=‘‘radio” name=‘‘gender”
value=‘‘male”> Male
<input type=‘‘radio” name=‘‘gender” value=‘‘female”>
Female<br><br>
Age: <select name=‘‘age”>
<option>18 to 25</option>
<option>25 to 35</option>
<option>35 to 50<option>
</select>
<br><br>I own: A bike <input type=‘‘checkbox”
name=‘‘vehicle”
value=‘‘Bike”>
A car <input type=‘‘checkbox” name=‘‘vehicle”
value=‘‘Car”>
An SUV <input type=‘‘checkbox” name=‘‘vehicle”
Web Technology 97
Unit 6 HTML Frames and Forms
value=‘‘Airplane”><br><br>
Hobbies: <br><br>
<select name=‘‘hobby” size=‘‘5’’ multiple=‘‘multiple”>
<option>Reading</option>
<option>Singing</option>
<option>Writing</option>
<option selected=‘‘selected”>Cooking</option>
<option>Travelling</option>
<option>None</option>
</select>
<br><br>
<input type=‘‘submit” value=‘‘Submit”>
<input type=‘‘reset” value=‘‘Reset”>
</form>
</body>
</html>
The above code gives the following output in Mozilla Firefox:
If we type some characters in the text fields above, and click the
“Submit” button, the browser will send the filled-in input to a processing
script “process.php” which is the value of the action attribute. The method
attribute defines how the input data is to be sent to the server.
z The <frameset> tag defines how to divide the window into frames.
z The noframes element is most used to link to a non-frameset version
of the web site or to display a message to users that frames are required.
z HTML forms are used to collect information from the user.
Top Top
Bottom
Left Right
7.2 INTRODUCTION
In the previous unit you have been introduced to HTML frames and
forms.
Web Technology 101
Unit 7 Cascading Style Sheet
In this unit, you will learn about Cascading Style Sheets and you be
introduced to Inline Style Sheets, Embedded Style Sheets, External Style
Sheets, and Imported Style Sheets. You will also learn to create CSS files
and to use CSS in web pages.
CSS stands for Cascading Style Sheets. CSS define how HTML
elements are to be displayed. CSS enables us to change the appearance
and layout of all the pages in a web site, just by editing in one single location.
CSS helps us save a lot of work since we have to specify the details only
once for an element. Due to less coding, pages are loaded faster. Since we
need to edit in only one place, the maintenance is easy. Also CSS has a
much wider array of attributes than HTML, hence having superior styles to
HTML.
p{
text-align:center;
color:black;
font-family:arial;
}
value 20px. This style is applicable only to the current instance of the element
<p>. This style is not applicable to the second <p> element.
<html>
<head>
<link rel=‘‘stylesheet” type=‘‘text/css”
href=‘‘mystyle.css”/>
</head>
<body>
<p>This is a paragraph.</p>
<p>This is an another paragraph.</p>
</body>
</html>
As we can see in the above example, an external style sheet
“mystyle.css” is applied by using the <link> tag. When we do any type of
change in the file “mystyle.css” or change the file name inside the <link>
tag, we can see the change in style in the whole web page.
As we can see in the above example, the @import rule is used inside
the <style> element which imports the style sheet from the given url.
We can also import style into the current style sheet by using the
@import style at the top of the CSS document.
@import “navigation.css”;
or
@import url(“navigation.css”);
A cascading style sheet (CSS) file can be created using any text
editor. Firstly the file should not contain any html tags. Then start writing the
style sheet by using any selector and its declaration (comprising a property
and its value). The style sheet should be saved with a .css extension. An
example of the contents of a style sheet file is shown below.
hr {color:red;}
p {margin-left:20px;}
body {background-image:url(“images/back40.gif”);}
#para1
{
text-align:right;
color:blue;
}
.center
{
text-align:center;
}
tool. Let us say we use Notepad in windows to create the html file. We use
inline cascading style sheet as the cascading style and hence the style is
applied to the each current element of the HTML document. Here we have
created an <div> element which contains two <p> elements.
<html>
<head>
</head>
<body>
<div style=‘‘border-style:solid;border-
color:black;border-
width:thick;width:200px;height:250px;
padding:5px”>
<p style=‘‘font-family:arial;font-
size:20px”>This is a paragraph of font-
family Arial and of font-size 20px.</p>
<p style=‘‘font-family:times;font-
size:15px”>This is an another paragraph
of font-family Times New Roman and of font-
size 15px.</p>
</div>
</body>
</html>
The output for the above written code for the html file is given below.
4.2 INTRODUCTION
In the previous units, you were introduced to various HTML tags and
also their different attributes having their own individual functions which can
be used in designing web-pages Style Sheets that offer a very flexible and
fast way to designing web-pages also featured in the previous unit. Style
Web Technology 113
Unit 8 Dynamic HTML
Sheets also allow us to control the style and layout of multiple web pages
all at once without much effort.
In this unit, we will discuss Dynamic HTML which enables us to
dynamically change the rendering and content of a web page as the users
interact with it. We will learn to create dynamic web pages to improve the
user interactivity.
z Embed a ticker that automatically refreshes its content with the latest
news, stock quotes, or other data.
z Use a form to capture user input, and then instantly process and
respond to that data.
DHTML achieves these effects by modifying the in-memory
representation of the current document and automatically reformatting it to
show changes. It does not reload the document, load a new document, or
require a distant server to generate new content. Instead, it uses the user’s
computer to calculate and carry out changes. This means a user does not
have to wait for text and data to complete the time-consuming roundtrips to
and from a server before seeing the results. Furthermore, DHTML does not
require additional support from applications or embedded controls to make
changes. Typically, DHTML documents are self-contained, using styles and
a script to process user input and directly manipulate the HTML elements,
attributes, styles, and text of the document.
In short, DHTML eliminates the shortcomings of static pages. We
can create innovative Web sites, on the Internet or on an Intranet, without
having to sacrifice performance for interactivity. Not only does DHTML
enhance the user’s perception of web-documents, it also improves server
performance by reducing requests to the server.
In the above code, the root node is <html>. All other nodes in the
document are contained within <html>.
The <html> node has two child nodes: <head> and <body>.
The <head> node holds a <title> node. The <body> node holds a
<h1> and <p> node.
A common error in DOM processing is to expect an element node to
contain text. However, the text of an element node is stored in a text node.
In this example: <title>DOM Tutorial</title>, the element node <title>,
holds a text node with the value “DOM Tutorial”.
“DOM Tutorial” is not the value of the <title> element!
The HTML DOM Node Tree: The HTML DOM views a HTML
document as a tree-structure. The tree structure is called a node-tree. All
nodes can be accessed through the tree. Their contents can be modified or
deleted, and new elements can be created.
The node tree below shows the set of nodes, and the connections
between them. The tree starts at the root node and branches out to the text
nodes at the lowest level of the tree:
Document
Root element:
<html>
Element: Element:
<head> <body>
Element:
<title> Attribute: Element: Element:
“href” <a> <h1>
Node Parents, Children, and Siblings: The nodes in the node tree
have a hierarchical relationship to each other. The terms parent, child, and
sibling are used to describe the relationships. Parent nodes have children.
Children on the same level are called siblings (brothers or sisters).
Web Technology 117
Unit 8 Dynamic HTML
<html>
<body>
<p id=‘‘intro”>Hello World!</p>
<script type=‘‘text/javascript”>
txt=document.getElementById(“intro”).innerHTML;
document.write(“<p>The text from the intro
paragraph: “+ txt’’ + “</p>”);
</script>
</body>
</html>
In the Example 8.2, getElementById is a method, while innerHTML
is a property.
Accessing Nodes: With the DOM, we can access every node in an
HTML document in three ways.
1) By using the getElementById() method which returns the element
with the specified ID.
2) By using the getElementsByTagName() method which returns all
elements with a specified tag name.
3) By navigating the node tree, using the node relationships.
getElementById() : This method returns the element with the
specified ID.
For example: document.getElementById(“intro”);
getElementsByTagName() : This method returns all elements with
a specified tag name.
For example: document.getElementsByTagName(“p”);
Navigating Node Relationships: The three properties; parentNode,
firstChild, and lastChild, follow the document structure and allow short-
distance travel in a document.
<html>
<body>
<p>Hello World!</p>
<div>
<p>The DOM is very useful!</p>
Web Technology 119
Unit 8 Dynamic HTML
link. Such events that trigger other changes to occur are discussed
at length later in this unit.
2) Real time positioning: When most people think of DHTML this is
what they expect– objects, images, and text moving around the Web
page. This can allow us to play interactive games with our readers
or animate portions of our screen. While straight HTML will allow us
some control of the position of elements through tables and using
the non-breaking space ( ), we can’t position things very
precisely. With Cascading Style Sheets (CSS) we can place an item
on a page at exact x and y coordinates. We will look into this feature
in the next section in more detail.
3) Dynamic fonts (Netscape Communicator): This is a Netscape only
feature. Netscape developed this to get around the problem
designers had with not knowing what fonts would be on a reader’s
system. With dynamic fonts, the fonts are encoded and downloaded
with the page, so that the page always looks as the designer intended
it to be. One of the most common uses of graphics on Web pages is
to create titles with the specific fonts we want displayed on our Web
site. The problem is, when we use a font tag or the font-family CSS
property, we have to hope that the readers have the fonts that we
specify on their computer.
For example, a company might have a font developed for them
for use as their official typeface, say “Company Font A”. In order to
get the most return on the investment of creating a new font, the
company wants the Web site to be displayed using that font. The
Web developers could use the CSS property:
font-family: Company Font A;
But this would only work on those computers that had that font
installed. In other words, only corporate computers would see the
font. Using dynamic fonts or embedded fonts, a Web developer can
use any font they wish to (Note: not all fonts can be embedded or
used as dynamic fonts) on their Web pages and have them
embedded so that their readers can view them as well. What this
Web Technology 121
Unit 8 Dynamic HTML
pages. The web pages containing CSS load faster into the user’s browser
hence allowing faster web access and navigation.
Positioning is the ability to place an HTML element at a specific
point on a page, relative to another element or the browser window itself.
While using CSS positioning, the first thing to be done is to use the CSS
property position to tell the browser if we are going to use absolute or relative
positioning. Then by assigning these coordinates, we can place elements
such as images, controls, and text exactly where needed. We can also assign
a z-index to define the order in which overlapping elements are stacked on
top of one another. There are four basic types of CSS positioning. They are:
1) Static positioning
2) Absolute positioning
3) Relative positioning
4) Fixed positioning
The CSS positioning properties allow us to specify the left, right,
top, and bottom position of an element. It also allows us to set the shape of
an element, place an element behind another, and to specify what should
happen when an element’s content is too big to fit in a specified area.
1) Static positioning: Static is the default position for any element on
a Web page. If we do not define the position, it will be static and will
display on the screen based on where it is in the HTML document
and how it would display inside the normal flow of the document.
If we apply positioning rules like top or left to an element that has a
static position, those rules will be ignored.
2) Absolute positioning: Absolute positioning is the easiest to
understand.
The CSS position property:
position: absolute;
tells the browser that whatever is going to be positioned should be
removed from the normal flow of the document and will be placed in
an exact location on the page. It is also taken out of the normal flow
of the document. It will not affect how the other elements before it or
after it in the HTML are positioned on the Web page.
124 Web Technology
Dynamic HTML Unit 8
</body>
</html>
The above code gives the following output in Mozilla Firefox.
We can very easily change the color of this text from within
JavaScript. The first step is to access the element using the getElementById()
method of the document object
myElement.style.color=‘‘green”;
Let us put this together in an example in which we have a button
configured to change the color of some text when it is pressed:
<html>
<head>
<title>JavaScript Radio Example</title>
<script type=‘‘text/javascript”>
function buttonPressed()
Web Technology 131
Unit 8 Dynamic HTML
{
var myElement=document.getElementById(“introtext”);
myElement.style.color=‘‘green”;
}
</script>
</head>
<body>
<p id=‘‘introtext”>‘‘This is some introductory text.
The color of the text sould change when the button
is pressed”</p>
<form action=‘‘name’’=‘‘orderForm”>
<input type=‘‘BUTTON” value=‘‘Click to change text
color” onClick=‘‘buttonPressed()”>
</form>
</body>
</html>
Example 8.7:The following example demonstrates how the font size
increases and changes its color when the user moves the mouse pointer
over it.
<html>
<head>
<title>Dynamic Styles</title>
<script type=‘‘text/javascript”>
function doChanges(e)
{
e.style.color = “green”;
e.style.fontSize = “20px”;
}
</script>
</head>
<body>
<h3 onmouseover=‘‘doChanges(this)” style=‘‘color:
black;font-size:18px”>Welcome to Dynamic HTML!</h3>
132 Web Technology
Dynamic HTML Unit 8
</h1>
</center>
<p id=‘‘para1’’>
This is the first paragraph on a simple page.
</p>
<p id=‘‘para2’’>
This is the second paragraph on a simple page.
</p>
</body>
</html>
Syntax : <element id=‘‘value”>
The ID attribute performs several actions for Web pages:
z A style sheet selector: This is the function most people use the id
attribute for. Because they are unique, we can be sure that we will
be styling just the one item on our Web page when we style using
an id property.
z Named anchors for linking to: Now, most modern Web browsers
allow us to target precise locations in a Web document by pointing
to the id at the end of the URL. We simply add the id to the end of
the page URL, preceded by a pound-sign (#).
z A reference for scripts: If we write any DHTML, we will want to use
the id attribute so as to make changes to the precise element on the
page with our scripts.
z A name for object elements: This acts in the same way as for scripts,
only we identify objects like Flash or Java.
z Other processing: The id allows us to process Web documents in
whatever way needed. For example, we might extract the HTML
into a database, and the id attribute identifies fields.
Rules for Using the ID Attribute: There are a few rules to be followed
to have a valid document that uses the id attribute anywhere in the document:
z The id must start with a letter (a-z or A-Z)
z All subsequent characters can be letters, numbers (0-9), hyphens
(–), underscores (_), colons (:), and periods (.).
z Each id must be unique within the document.
134 Web Technology
Dynamic HTML Unit 8
DHTML events are nothing but handlers that can trigger actions in a
browser. The Event object represents the state of an event, such as the
element in which the event occurred, the state of the keyboard keys, the
location of the mouse, and the state of the mouse buttons.
Events are normally used in combination with functions, and the
function will not be executed before the event occurs. Every element on an
HTML page has events which can trigger a JavaScript. For example, we can
use the onClick event of a button element to indicate that a function will run
when a user clicks on the button. We define the events in the HTML tags.
Examples of events:
z A mouse click
z A web page or an image loading
z Mousing over a hot spot on the web page
z Selecting an input field in an HTML form
z Submitting an HTML form
z A keystroke
Some of the attributes that can be inserted into HTML tags to define
event actions are:
onclick Mouse clicks on object
ondblcick Mouse double-clicks an object
onblur Anelement loses focus
onabort Loading of an element is interrupted
oncharge The content of a field changes
onreset The reset button is clicked
onselect Text is selected
onload A page or an image has finished loading
onunload The user exits the page
onsubmit The submit button is clicked
onresize A window or frame is resized
onerror An error occurs when loading a document or an image
onmousedown A mouse button is pressed
onmousemove The mouse is moved
onfocus An element gets focus
Example 8.9: In the following example, the content of the h1 element
will change when a user clicks on it:
136 Web Technology
Dynamic HTML Unit 8
<html>
<body>
<h1 onclick=‘‘this.innerHTML=‘‘Ooops!’’>Click on
this text</h1>
</body>
</html>
We can also add the script in the head section,and then call a function
from the event handler as shown below:
<html>
<head>
<script type=‘‘text/javascript”>
function changetext(id)
{
id.innerHTML=‘‘Ooops!”;
}
</script>
</head>
<body>
<h1 onclick=‘‘changetext(this)”>Click on this text</h1>
</body>
</html>
Example 8.10: This example asks for user input, and on clicking
OK button redirects the user to www.kkhsou.org.
<html>
<head>
<script type=‘‘text/javascript”>
function confirmInput()
{
fname=document.forms[0].fname.value;
alert(“Hello’’ + fname + “! You will now be redirected to
www.kkhsou.org”);
}
</script>
Web Technology 137
Unit 8 Dynamic HTML
</head>
<body>
<form onsubmit=‘‘confirmInput()” action=‘‘http://
www.kkhsou.org/”>
Enter your name: <input id=‘‘fname” type=‘‘text”
size=‘‘20">
<input type=‘‘submit”>
</form>
</body>
</html>
Example 8.11: In this example an alert box is triggered whenever
the text box is clicked (gets focus).
<html>
<head>
<script type=‘‘text/javascript”>
function message()
{
alert(“This alert box was triggered by the onfocus
event handler”);
}
</script>
</head>
<body>
<form>
Enter your name: <input type=‘‘text”
onfocus=‘‘message()” size=‘‘20’’>
</form>
</body>
</html>
Ans. to Q. No. 1: i) DHTML; ii) static; iii) DOM, objects; iv) text, node;
v) tree-structure; vi) innerHTML.; vii) getElementById()
Ans. to Q. No. 2: i) four; ii) stylesheet; iii) background-image; iv) three;
v) browser; vi) space
Ans. to Q. No. 3: i) three; ii) functions; iii) DHTML; iv) object; v) process
Sl.
Statements
No.