web programming
web programming
WEB PROGRAMMING
(As per the new syllabus and revised examination)
By:
Venu P. B.E. Comp.
Published by:
DISC Computers.
Apoorva Degree College.
SYLLABUS
WEB PROGRAMMING
Max. Marks : 100 (Theory 70 + Practical 30)
UNIT - I:
HTML Programming Introduction - Formatting Text-Forms & Formulating Elements -
Graphics in HTML Creating Tables & Frames - Web Design Principles.
UNIT- II :
VB Scripting Introduction - VB Script - Basics of VB Script - Array Handling - User Interaction
in VB Script - Data Validation in VB Script - Handling Runtime Errors.
UNIT - III :
Dynamic HTML Programming Introduction - Cascading Style Sheets (CSS) - Events Handling -
Changing Text and Attributes - Dynamically Changing Style, Text, Graphics and Placements -
Creating Multimedia Effects with Filters and Transitions.
UNIT - IV:
Active Server Pages (ASP) Introduction - Scripting Languages and Script Engines in ASP - ASP
Objects - Data Access Technology - ASP Application - Information Search Tools.
UNIT- V :
Extensible Markup Language (XML) Introduction - Creating XML Documents - XML Style
Sheets - Hyperlinks in XML Documents - XML Document Object Model - XML Query
Language.
Lab Work:
Creation of a Web site with Dynamic functionality using client-side and server - side
scripting.
Suggested Reading:
1. Microsoft Official Curriculum.
2. Essential XML : Box
3. Dynamic HTML : Rule
4. HTML for the WWW : Castro
1 HTML
1. What is HTML? Explain its Advantages and Disadvantages.
2. What is a Tag? Explain Tag Properties.
3. What is the structure of a HTML page?
4. What are Attributes? What are the Common or Standard Attributes of HTML tags?
5. Explain the attributes of <BODY> tag.
6. Explain <HEAD> tag in detail. (OR) Explain HEAD section in a HTML document. (OR)
What tags can be included in <HEAD> tag?
7. What are Text (Character) formatting tags in HTML? (Or) What are Physical Tags in
HTML?
8. Write about Paragraph Formatting tags.
9. Explain different Formatting tags in HTML?
10. What are Logical Tags in HTML? Explain.
11. Distinguish between Physical HTML style tags and Logical HTML style tags. (Or)
Distinguish between Dependent Tags and Independent Tags with two examples for
each tag.
12. Write about different Heading tags.
13. How do you write Comments in HTML documents?
14. Write short notes on <FONT> tag.
15. Write short notes on <MARQUEE> tag. And explain its attributes. (Or) How to
create scrolling text/images in HTML?
16. Write short notes on <IMG> (Image) tag. (Or) How to add images to HTML pages?
17. How do you place objects or multimedia content in HTML pages? (Or) How do you
play Audio and Video files in HTML?
18. Explain Graphics of HTML with the help of an example.
19. Explain ALIGN attribute in images. (Or) How do you align Images with respect to
text?
20. What is Image Mapping? (Or) Write short notes on <MAP> and <AREA >tags.
21. Write about different types of Lists in HTML.
22. Write about <TABLE> tag. (Or) How do you create tables in HTML?
23. Using table and its sub-tags Design a Students Marks Memorandum
24. Using table and its sub-tags create the following table.
25. Explain the table alignment attributes and cell alignment attributes. (Or) Explain
horizontal and vertical alignment in Tables with an example.
26. Write about Column spanning and Row spanning in tables with an example. (Or)
Explain Spanning columns and Rows in a table with the help of an example.
HTML: HTML stands for Hyper-Text Markup Language. It allows us to create web pages.
It does not include any control structure and can produce only static content. A HTML
page consists of various tags that make a web page. The features, advantages and
disadvantages of HTML page are listed below.
Features of HTML:
It is a formatting language for text and images.
It allows us to read the content nonlinearly by using hyperlinks to a file.
HTML is an application of SGML.
HTML uses markup tags to describe web pages
It is not case sensitive i.e. code can be written in small case or uppercase letters.
All the HTML documents have “.html” or “.htm” extension.
HTML documents can be edited using editors such as notepad or front page.
HTML Tags: HTML uses markup tags to describe web pages. HTML markup tags are
usually called HTML tags. The properties of tags are listed below.
Element
A HTML document is basically separated in two parts: the head (HTML head tag) and
the body (HTML body tag). We also add a Document type declaration on top of it to get
the basic document structure and HTML version. The structure of a HTML document is
shown below.
<HTML> tag: The html tag acts as a container for the whole document. Every
character in the document should be in between the html start and end tags. The
html tag can also be used to define the language of the contained document
through the "lang" attribute. The content of the html tag is divided in two parts
using the head (HTML head tag) and the body (HTML body tag).
<HEAD> tag: This section is the document's head. All the information contained in
the document's head is loaded first, before any other thing in the document, as it's
defined before the body segment. It includes tags like title, script, style, meta and
so on.
<BODY> tag: This is the document's body: The body is the container for the visual
part of a document. All the things written here will be shown when the document
is rendered. Most of the tags in HTML can be inserted in the body section (inside
the HTML body tag) and will take care of the visual aspects of the document.
Example:
<HTML>
<HEAD>
<TITLE> My first Page </TITLE>
</HEAD>
<BODY>
<H1> Hello HTML <H1>
</BODY>
</HTML>
4. What are Attributes? What are the Common or Standard Attributes of HTML tags?
Attributes: Attributes provide additional information about an element (tag). All the
tags can have attributes. And these attributes are always specified in the start tag. The
following are the characteristics of attributes.
Attributes have default values
Attributes come in name/value pairs like: attribute-name="value"
There are some valueless attributes like ‘checked’ in <input> tag.
Some of the attributes are required in some of the tags. For example, ‘src’
attribute of <IMG> tag is mandatory.
Example: The following <FONT> tag uses ‘color’ and ‘size’ attributes.
<font color=’red’ size=8> Hello APOORVA </font>
<BODY> tag: This is the document's body: The body is the container for the visual part
of a document. All the things written here will be shown when the document is
rendered. Most of the tags in HTML can be inserted in the body section (inside the
HTML body tag) and will take care of the visual aspects of the document.
When we create a Web page, we can change several visual characteristics in the body
of the document by adding extra attributes to the <body> tag. Following are the
different attributes, which can be used in BODY tag.
Bgcolor: This changes the background color of the page. We can set this to any
color we would like to use. We can give color name or hex code.
Text: This changes the default text color in the page. Here also, we can give color
name or hex code.
Link: This changes the color of all the non-visited links on the page.
Alink : This changes the color of an active link on the page, which is a link that has
just been clicked on by a user.
Vlink: This changes the color of a visited link on the page
Background: This adds a background image to the page. If we don't use a
background image, the browser will use the background color or its default
background color.
Example: Following code uses the above attributes in the body tag.
<HEAD> tag: This section is the document's head. All the information contained in the
document's head is loaded first, before any other thing in the document, as it's defined
before the body segment. It includes tags like title, script, style, meta, base, basetag,
index and so on.
<TITLE> tag: This is the document's title. This is displayed in the title bar of the
window.
<STYLE> tag: This is used to write style specifications. It includes a group of class
definitions (style sheets) used by other tags to set visual characteristics.
<SCRIPT> tag: This allows defining script functions which are of VBScript and
JavaScript.
<META> tag: This has information about data. This sets custom attributes and
values for the document.
<LNIK> tag: This is used to specify global links. This specifies relationships with
other documents.
<ISINDEX> tag: This is for simple keyword searches
<BASE tag>: This defines default address/directory for the links in a HTML page.
<BASEFONT> tag: This tag specifies a default font-color, font-size, or font-family
for all the text in a document.
<head>
<title> C Notes </title>
<meta name="Author" content="Venu" />
<base href=“http://winningbrains.com/images/” />
<basefont color="red" size="5" />
<style>
table
{
border-width: 100%;
border-color: blue;
}
</style>
<script language="VBScript">
sub sayhi
msgbox "hi"
end sub
</script>
<link rel="index" href="../index.html" />
</head>
7. What are Text (Character) formatting tags in HTML? (Or) What are Physical Tags in
HTML?
Formatting tags: Formatting tags are used to apply formatting to the text. They render
the text in different formats according to the tag used. The common formatting tags
are listed below. The listed tags are known as physical tags. Physical tags define how
the text should be displayed in the browser. They control the Physical characteristics of
the text.
Tag Description
<b> Defines bold text
<i> Defines italic text
<u> Defines underlined text
<big> Defines big text
<small> Defines small text
<sub> Defines subscripted text
<sup> Defines superscripted text
<tt> Defines teletype text
<strike> Strikes off the text
<blink> Makes the text blinking
<font> Allows us to set font-face, color and size
<center> Aligns the text in center
Example:
<html>
<body> Output:
<B>Hello </B> <BR>
<I> Hello </I> <BR>
<U> Hello </U> <BR>
H<sub>2</sub>O <BR>
x<sup>2</sup>y <BR>
<TT>Hello<TT> <BR>
<strike>Hello</strike>
<BR>
<blink>Hello</blink> <BR>
<font face="arial"> Hello
</font>
<center>Hello</Center>
<BR>
</body>
</html>
Paragraph Formatting Text: The following tags are used to format a paragraph. When
used, they create new paragraphs by introducing new line to the text written in them.
Tag Description
<div> It defines a division in the document
<p > It defines a paragraph
<pre> Preformatted text, it writes text exactly as it is,
including spaces.
<br> forces the browser to start a new line
<blockquote> Blockquote produces text that is indented in from both
the left and right margins.
<address> This tag is used to enclose information such as
"address, signature and authorship"
<center> Center aligns the text/paragraph
<xmp> Similar to preformatting tag; it also ignores the html
code with in this tag.
<h1>, <h2>,..<h6> Generates headings in different sizes
Example: Output:
<html> New Section
<body>
<div> New Section </div>
<p> I am a paragraph </p> I am a paragraph
<pre>too many spaces</pre>
<blockquote> Note this too many spaces
point</blockquote> Note this point
<address> Ravi, 7/G, Brindavan Ravi, 7/G, Brindavan Colony
Colony </address>
<br> Text in the Next Line
<center> Centered Text</center> Text in the Next Line
<xmp>Even tags as they are: Centered Text
e.g.<h1>hi</h1> </xmp> Even tags as they are:
</body> e.g.<h1>hi</h1>
</html>
Logical Tags: Logical tag tells how the text is being used. They indicate the 'type' of
content they enclose. They do not determine the display of the text and the browser is
free to determine its display style. There are tags for emphasizing important sections of
text, for definitions and citations, computer output and other data.
Tag Description
<strong> Defines strong text
<em> Defines emphasized text
<ins> Defines inserted text
<del> Defines deleted text
<code> Defines computer code text
<kbd> Defines keyboard text
<samp> Defines sample computer code
<var> Defines a variable
<abbr> Defines an abbreviation
<acronym> Defines an acronym
<bdo> Defines the text direction
<address> Defines an address element. This tag is used to enclose
information such as "address, signature and authorship"
<blockquote> Defines a long quotation. Blockquote produces text that is
indented from both the left and right margins.
<q> Defines a short quotation
<cite> Defines a citation
<dfn> Defines a definition term
<mark> Intended to be highlighted
Example: Following lines of code uses some of the above tags. Output is shown.
11. Distinguish between Physical HTML style tags and Logical HTML style tags.
(Or) Distinguish between Dependent Tags and Independent Tags with two
examples for each tag.
Physical Tags:
Physical tags define how the text should be displayed in the browser.
They control the Physical characteristics of the text.
They are browser independent and hence known as independent tags.
That is, they are rendered same in different browsers.
Some of the physical tags are: <B>, <I>, <U>, <SUP>, <SUB> and so on.
Logical Tags:
Logical tags indicate the 'type' of content they enclose.
They do not determine the display of the text and the browser is free to determine
its display.
They are browser dependent and hence known as dependent tags.
That is, they may be rendered differently in different browsers.
Some of the logical tags are: <EM>, <STRONG>, <ADDRESS>, <CODE>, <SITE> and
so on.
Heading Tags: Headings are most common type of inclusion in any writing. It can be
used to divide the page into sections. In HTML there are six types of heading tags. <H1>
to <H6>. When we use headings, they automatically appear in new lines. The following
program uses different heading tags.
<html> Output:
<body>
<h1>Hello </h1>
<h2>Hello </h2>
<h3>Hello </h3>
<h4>Hello </h4>
<h5>Hello </h5>
<h6>Hello </h6>
</body>
The comment tag is an empty tag in which the comment is placed. The beginning of the
tag is "<!--" and the end of the tag is "-->". Any tags placed within the comment are
ignored by the browsers.
Syntax:
<!-- text -->
Example:
<BODY>
<!-- My First Greetings -->
<H1> Hello </H1>
</BODY>
Font Tag: The font tag is used to control the formatting of the text on the web page. It
has several useful attributes:
Color: color specifies the font color. We can specify the color name or the hexadecimal color
code.
Size: size is a number from 1 to 7 that defines the size of the text, with 1 being the smallest.
The standard text size is 3.
Face: face is a text string that defines the font face which takes the values such as
"verdana", "times new roman", "arial", etc.
Example: If we want to display some text in blue color using large font size and in the
Verdana font, we use the following HTML code:
<font face="verdana" size="6" color="blue">
Hi Apoorva
</font>
We can also embed one font tag in the other (it display ‘APOORVA’ in red color and the
rest in blue color):
<font face="Arial" color="blue"> I am a Student of
<font color="red"> APOORVA </font> College </font>
15. Write short notes on <MARQUEE> tag And Explain its Attributes. (Or) How to create
scrolling text/images in HTML?
Creating Scrolling Text: The <MARQUEE> tag is used to create a scrolling text or image.
A marquee can be made to scroll from left to right or right to left. Attributes of the
<MARQUEE> tag are:
Example: The following code scrolls the text from right to left.
<html>
<marquee bgcolor=yellow> WELCOME TO APOORVA </marquee>
</html>
16. Write short notes on <IMG> (Image) tag. (Or) How to add images to HTML pages?
<IMG> Tag: We use the Image tag to place images in web pages. The Image tag has no
closing tag. But, it has one required attribute (src), along with few other attributes.
Src: identifies the URL of the image and must be enclosed in quotes. This is a
required attribute.
Alt: provides alternative text in case the image doesn't load. The alt text also
appears if the user moves the mouse cursor over the image for a few seconds.
Width, height: They specify the width and height of the image. If we only specify
one of these, the image will maintain it's aspect ratio, so we generally need to
indicate one or the other. The number specified can represent the size in pixels or
a percentage of the original width and/or height.
Align: specifies how the image should be aligned with respect to surrounding text.
The options are top, middle, bottom, left and right.
Vspace, Hspace: Specifies right and left side spacing in the case of hspace and top
and bottom spacing in the case of vspace.
Border: Specifies border width around the image.
Usemap: Specifies an image as client side image map.
To make the image 200 x 100 pixels in size, we use the following code.
<img src="www.smartclass.co/images/logo.jpg" alt="My Logo"
width="200" height="100">
17. How do you place objects or multimedia content in HTML pages? (Or) How do you play
Audio and Video files in HTML?
a) Object Tag: The object tag tells browser to include a multimedia application. The
browser retrieves the file specified in the DATA attribute. Other attributes are class id,
code type, hspace and etc.
Example: <object data=“abc.wrl” height=“200” width=“200”>
</object>
b) Embed tag: The embed-tag is similar to the object tag in that it allows us to include
multimedia in an HTML document.
Example: <embed src=“pokiri.mid” height=“200” width=“200”>
HTML 5.0 added two new tags <AUDIO> and <VIDEO> to play audio and video files.
Graphics can be easily added to html pages using tags like <marquee>, <img>, <object>
and <embed> tags. That is, using these tags we can create the following.
1. Scrolling Text/Images
2. Adding images
3. Adding Multimedia objects or Audio/Video Content.
1. Creating Scrolling Text: The <MARQUEE> tag is used to create a scrolling text or
image. A marquee can be made to scroll from left to right or right to left.
Attributes of the <MARQUEE> tag are: align, direction, bgcolor, height, width and
etc.
Example: The following code scrolls the text from right to left.
<html>
<marquee bgcolor=yellow> WELCOME TO APOORVA </marquee>
</html>
2. Adding Images: We can add images using <IMG> tag of html. We can easily control
it’s alignment, height and width using its attributes. The Image tag has no closing
tag. But, it has one required attribute (src), along with few other attributes like
height, width, alt, align, hspace, vspace and so on.
Example: The following code displays an image.
<img src="logo.jpg" alt="My Logo" width="200"
height="100">
19. Explain ALIGN attribute in images. (Or) How do you align Images with respect to text?
We use the Image tag to place images in web pages. The Image tag has no closing tag.
But, it has one mandatory attribute (src), along with few other attributes. One of the
important attribute is ‘align’, which is used to specify how the image should be aligned
with respect to surrounding text. The options are top, middle, bottom, left and right.
Example: The following code displays images with left and right alignment options. The
output is also shown.
20. What is Image Mapping? (Or) Write short notes on <MAP> and <AREA >tags.
Image mapping allows us to create clickable regions on a single image. These clickable
regions act like hyperlinks which on clicking open other documents or take us to other
locations. These are also known as hotspots. For this, we use <AREA> and <MAP> tags.
To create hotspots i.e. image mapping we follow the three steps listed below:
1. Create an image and set value (name of a map) to the attribute ‘usemap’.
2. Create the map identified by the name used in ‘usemap’. This includes <area>
tags to create clickable regions.
3. Create the clickable regions (rect or circle or polygon) by specifying
coordinates.
Example: The following program creates three hotspots (clickable regions) on the
image “planets.gif” using <IMG>, <MAP> and <AREA> tags.
<html>
<body>
<p>Click on the sun or on one of the planets </p>
<img src="planets.gif" width="145" height="126"
alt="Planets" usemap="#planetmap" />
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" alt="Sun"
href="sun.html" />
<area shape="circle" coords="90,58,3" alt="Mercury"
href="mercury.html" />
<area shape="circle" coords="124,58,8" alt="Venus"
href="venus.html" />
</map>
</body>
</html>
Output:
HTML allows mainly three types of lists. They can be used for giving numbers and
bullets to the lists. We can also nest the lists. The three types are:
1. Ordered List (OL)
B- Com III – Web Programming
22 Apoorva Publishers
2. Unordered List (UL)
3. Definition List (DL)
1. Ordered List: This gives numbering to the list items. The numbering could be
Arabic numerals or roman numeral or alphabets depending on the value of the
‘type’ attribute of ordered list. The tag used is ‘<OL>’. The different values of ‘type’
can be:
Type Description
1 The default. Uses Arabic numerals.
I Uses uppercase Roman numerals.
i Uses lowercase Roman numerals.
A Uses uppercase letters.
a Uses lowercase letters.
<html>
<body> Output:
<h1>Select a Fruit </h1>
<OL>
<LI> APPLE </LI>
<LI> MANGO </LI>
<LI> BANANA </LI>
</OL>
</body>
</html>
If we change the ‘type’ value to ‘I’ i.e. to get roman numerals, it is going to be like
this.
2. Unordered List: This gives bullets to the list items. The bullets could be square
type, circle type depending on the value of the ‘type’ attribute of ordered list. The
tag used is ‘<UL>’. The different values of ‘type’ can be:
Type Description
disc The default. Uses a filled circle.
circle Uses a hollow circle.
square Uses a filled square.
<html> Output:
<body>
<h1>Select a Fruit </h1>
<UL>
<LI> Apple </LI>
<LI> Mango </LI>
<LI> Banana </LI>
</UL>
</body>
</html>
3. Definition List: A kind of listing in which the definition term using <DT> and its
description using <DD> can be taken. The following list demonstrates the definition
list. The tag used for definition list is ‘<DL>’.
<html> Output:
<body>
<h1> ONLINE TUTORIAL</H1>
<DL>
<DT> HTML </DT>
<DD> Hyper Text Markup
Language </DD>
<DT> WWW</DT>
<DD> World Wide Web</DD>
<DT> CGI </DT>
<DD> Common Gateway
Interface</DD>
</DL>
</body>
</html>
22. Write about <TABLE> tag. (Or) How do you create tables in HTML?
<TABLE> tag: To produce tables in html, we use <table> tag. The entire table element is
delimited by the <TABLE> and </TABLE> tags. It requires additional tags such as <th>,
<tr> and <td>, which are explained below.
<TR>: This tag is used to define a Table Row. Each table row is delimited by the <TR>
and </TR> tags. Table rows are nested within the table element described above.
<TD>: This tag is used to define Table Data i.e. value in each cell. Each cell (or table
data) is delimited by the <TD> and </TD> tags. The cells are nested within the table row
element.
Example:
<html>
<html>
<body>
<h1> Marks Memo </H1>
<table bgcolor=yellow border=1
width=200>
<tr>
<th> Name </th> <th> Rno </th>
<th> Marks </th>
</tr>
<tr> Output:
<td> Ravi </td>
<td> 500 </td>
<td> 33 </td> Marks Memo
</tr> Name Rno Marks
<tr>
<td> Kiran </td> <td> 44 </td>
<td> 600 </td> Ravi 33 500
</tr>
<tr>
<td> Raju </td> <td> 55 </td> Kiran 44 600
<td> 700 </td>
</tr>
</table> Raju 55 700
</body>
</html>
Attribute Description
align Specifies the alignment of a table according to surrounding
text. Values can be: left, center, right
bgcolor Specifies the background color for a table
border Specifies the width of the borders around a table
cellpadding Specifies the space between the cell wall and the cell content
cellspacing Specifies the space between cells
width Specifies the width of a table
23. Using table and its sub-tags Design a Students Marks Memorandum
24. Using table and its sub-tags create the following table.
B- Com III - Web Programming
Apoorva Publishers 25
Horses Race Time
Blueball Fortbell 5.25
Blue Prince Fortbell 6.5
To create the above table, we use <TABLE> tag and the sub-tags of <TABLE> tag <TR>,
<TD> and <TH>.
<TABLE> tag: To produce tables in html, we use <table> tag. The entire table element is
delimited by the <TABLE> and </TABLE> tags.
<TR>: This tag is used to define a Table Row. Our sample table has four horizontal rows.
Each table row is delimited by the <TR> and </TR> tags. Table rows are nested within
the table element.
<TD>: This tag is used to define Table Data i.e. value in each cell. Each cell (or table
data) is delimited by the <TD> and </TD> tags. The cells are nested within the table row
element.
<TH>: This tag produces a row, which is normally used has header row. Each table
header is delimited by the <TH> and </TH> tags. Most browsers display the content of
a table header cell in boldface.
25. Explain the table alignment attributes and cell alignment attributes. (Or) Explain
horizontal and vertical alignment in Tables with an example.
In a table, the content of each cell can align horizontally and vertically using different
options. The ‘align’ attribute of table specifies the alignment of table itself according to
surrounding text. But, the ‘align’ attribute of <td> aligns the text within the cell.
That is, to align text with the cells we make use of two tags: 1. Align and 2. Valign
1. Align: This aligns the text horizontally in the cell, the possible values for this
attribute are:
Value Description
left Left-align content (default for td elements)
right Right-align content
center Center-align content
justify Stretches the lines so that each line has equal width
Example: The following table uses ‘align’ attribute with different values.
2. Valign: This aligns the text vertically in the cell, the possible values for this
attribute are:
Value Description
Top Top-align content
middle Center-align content
bottom Bottom-align content
baseline Alignment as per the baseline
26. Write about Column spanning and Row spanning in tables with an example. (Or) Explain
Spanning columns and Rows in a table with the help of an example.
In HTML, a table can have rows and columns evenly or sometimes a cell can span in
multiple columns or in multiple rows. To achieve this, we use colspan, rowspan
attributes of <TD> tag. Consider the following examples.
Spanning Column: The following code displays a table that has a cell
which spans in two columns. For this, we used colspan=2 for the cell of the
first row.
Output:
<table border=1 width=300>
<tr> <td colspan=2> APOORVA APOORVA
</td> </tr>
<tr> <td> Degree College </td>
<td> MBA College </td> </tr> Degree College MBA College
</table>
Spanning Row: The following code displays a table that has a cell, which
spans in two rows. For this, we used rowspan=2 for the first cell of first row.
<table border=1 width=300> Output:
<tr> <td rowspan=2> APOORVA Degree College
</td> <td> Degree College
</td></tr> APOORVA
<tr> <td> MBA College </td> MBA College
</tr>
</table>
27. Explain how to create a table and design the Border, Horizontal, Vertical
alignment, Spanning columns and Rows in a table with the help of an example.
28. How do you create links in HTML? (Or) Write about <A HREF> tag.
A link or hyperlink is some highlighted text which on clicking takes to other page, or
other website or another location in the same page. Hyperlinks facilitate non-linear
reading. HTML allows us to create hyperlinks using anchor tag. Anchor tag has one
mandatory attribute ‘href’ which specifies the target page or location. The text that
acts like hyperlink should be delimited by <a> and </a>. An anchor can point to any
resource on the Web: an HTML page, an image, a sound file, a movie, etc.
Examples:
The following link which on clicking takes to a website
<a href="www.winningbrains.com”> See More </a>
The following link which on clicking takes to another page in the same website
<a href="../index2.html”> Learn More </a>
The following link which on clicking takes to another location in the same page. For
this, we need to assign a name to the target location.
<a href="#advantages"> See advantages </a>
………
<a name=”advantages”> … </a> …
The following link which on clicking opens an image
<a href=”logo.gif”> See The Logo </a>
The following link which on clicking opens the page in a new window.
<a href="../index2.html” target=”_blank”> Do More </a>
The commonly used attributes of the anchor tag are shown below.
Example: The following link which on clicking opens the page in a new window. This
uses ‘target’ attribute.
<a href="../index2.html” target=”_blank”> Learn It </a>
30. Write short notes on ‘target’ attribute of anchor tag. (Or) Explain how to open
documents trough hyperlinks in different ways (targets)
A link or hyperlink is some highlighted text which on clicking takes to other page, or
other website or another location in the same page. It uses an attribute called ‘target’,
which specifies where to open the linked document.
TARGET controls where the new document will be displayed when the user follows a
link. Most of the time, clicking on a link simply loads a new document in the same
window where the link is. However, with TARGET, we can have the new document
open in a new window, or in another frame or in the same or parent window.
Example: The following link, which on clicking opens the page in a new window. This
uses ‘target’ attribute.
<a href="../index2.html” target=”_blank”> Learn It </a>
31. How do you make an image as a hyperlink? (Or) How to create Graphical
Hyperlinks in HTML? Give an example.
Not only text can be made as a hyperlink, but also images can be made as hyperlinks.
Thus, when clicking on the given image, it opens the linked document or takes to a
book-marked location. This is something like creating graphical hyperlink.
This can be achieved with the same anchor tag <a>. Between the pair of an anchor
tag, we use <img> tag to make an image as hyperlink. This technique can be used to
display thumb nails which on clicking open the enlarged images or to represent
companies/sites by some images or by their logos, which is much effective than
displaying text.
Example:
The following codes display two image, which on clicking takes to the linked
websites.
<a href="www.winningbrains.com”>
<img src=”brain.jpg”>
</a>
<a href="www.wikipedia.com”>
<img src=”wikilogo.jpg”>
</a>
32. Write about Background animations in HTML pages. (Or) Write about background
images and sounds.
Background Music: Background sound can be added using the tags <bgsound>.
The two main attributes it takes are ‘src’ and ‘loop’. The loop attributes determines
the number of times the audio file is played.
Example: <BGSOUND SRC="MySong.wav" LOOP=INFINITE >
33. What are Form Elements (Components)? Explain. (Or) Explain <FORM> tag in detail.
Forms: Forms are the most popular way to make web pages interactive. Like forms on
paper, a form on a web page allows the user to enter requested information and
submit it for processing.
<FORM> tag: The <form> tag is used to create an HTML form for user input. A form can
contain input elements like text fields, checkboxes, radio-buttons, submit buttons and
more. A form can also contain select menus, textarea, and label elements. Forms are
used to pass data to a server.
<FORM>
name: <INPUT TYPE=TEXT NAME=pname> <BR> name:
password: <INPUT TYPE=PASSWORD
NAME=email> <BR> password:
<INPUT TYPE=SUBMIT>
</FORM> Submit Query
This tag takes two main attributes: TYPE and NAME. TYPE indicates what kind of
element should appear on the form. NAME assigns a name to go with the input field.
The ‘type’ attribute can take any of the following values.
Text: Provides a single line text box.
Textarea: Provides a multiline text box.
Password: Same as the TEXT type, but characters are displayed as asterisks.
Button: Creates a button with which a user can initiate some action.
Submit: Creates a button labeled "submit". This on clicking sends information from
form-elements to a server.
Reset: Creates a button labeled "reset" in the form. Using this, a user can clear the
values of the form elements.
Checkbox: Produces an on-screen check box for users to make multiple choices
Radio: Creates a radio button for a range of selections from which the user may
select only one.
File: This displays a text box along with a “browse” that allows us to select files
from local computer. The selected file appears in the text box.
<FORM>
name: <INPUT TYPE=TEXT NAME=pname> <BR> name:
password: <INPUT TYPE=PASSWORD
NAME=email> <BR> password:
<INPUT TYPE=SUBMIT>
</FORM> Submit Query
<LEGEND> is used with <FIELDSET> to give a title to each set of fields. This is very useful
to show the separation of groups with a border and title and it is more visually
appealing.
The <fieldset> tag is used to logically group together elements in a form.
The <fieldset> tag draws a box around the related form elements.
The <legend> tag defines a caption for the fieldset element.
Example: Output:
<FIELDSET>
<LEGEND> Personal Details
</LEGEND>
<BR>
name: <INPUT NAME="pname">
<BR>
email: <INPUT NAME="email">
</FIELDSET>
37. Write short notes on <FRAME> tag. (Or) Explain Frames in HTML? (Or) What is a
Frameset? Explain how to create Horizontal and Vertical Frames.
In HTML, frames enable us to present multiple HTML documents within the same
window. For example, we can have a left frame for navigation and a right frame for the
main content.
Frames are achieved by creating a frameset page, and defining each frame from within
that page. This frameset page doesn't actually contain any content - just a reference to
each frame. The HTML <frame> tag is used to specify each frame within the frameset.
All frame tags are nested with a frameset tag.
So, in other words, if we want to create a web page with 2 frames, we would need to
create 3 files - 2 files for two frames, and 1 file to specify how they fit together.
The frameset Tag Attributes: In the frameset tag, we specify either cols or rows,
depending on whether we want frames to be displayed vertically or horizontally. The
common attributes in <frameset> tag are:
Attribute Description
rows Specifies the number of rows and their height in pixels, percentages,
or relative lengths. Default is 100%
The frame Tag Attributes: For each frame we want to display, we specify a frame tag.
We nest these within the frameset tag. The common attributes in <frame> tag are:
Attribute Description
name Assigns a name to a frame. This is useful for loading contents
into one frame from another.
src Location of the frame contents (for example, the HTML page to
be loaded into the frame).
noresize Specifies whether the frame is resizable or not (i.e. whether the
user can resize the frame or not).
scrolling Whether the frame should be scrollable or not (i.e. should
scrollbars appear). Possible values are : yes, no, auto
frameborder Whether the frame should have a border or not. Possible values
are : 0 or 1
marginwidth Specifies the margin, in pixels, between the frame's contents
and it's left and right margins.
marginheight Specifies the margin, in pixels, between the frame's contents
and it's top and bottom margins.
Example: Following program uses three vertical frames. Before writing this, the user
needs to create three HTML files to be displayed in each frame. Here, ‘a1.html’,
‘a2.html’ and ‘a3.html’.
<html> Output:
<frameset cols="25%,50%,25%">
<frame src='a1.html'>
<frame src='a2.html'>
<frame src='a3.html'>
</frameset>
</html>
<html>
<frameset
rows="50%,30%,20%">
<frame src='a1.html'>
A nested frame is a frame within another frame. Here, we need to use one frameset in
another frameset. The second frameset comprising two or more other frames takes the
position of second frame in the outer frameset.
Example: Following program uses nested frames. The outer frameset uses horizontal
farming and the inner frameset uses vertical framing. Here, ‘a1.html’, ‘a2.html’ and
‘a3.html’ have to be created first.
Output:
<html>
<frameset rows="50%,50%">
<frame src='a1.html'>
<frameset cols="50%,50%">
<frame src='a2.html'>
<frame src='a3.html'>
</frameset>
</frameset>
</html>
College Name
College Logo Courses Offered
B.SC.
B.Com.
B.A.
College.html
<html>
<body>
<center> <h4> College Name :</h4>
<h4> APOORVA DEGREE COLLEGE </h4> </center>
</body>
</html>
Logo.html
<html>
<body>
<center> <h4> College Logo:</h4>
<img src="apoorva.gif" width=100></center>
</body>
</html>
Course.html
<html>
<body>
<center> <h4> COURSES OFFERED </h4> </center>
<ul type=square>
<li> B.Sc. </li>
<li> B.Com. </li>
<li> B.A. </li>
</body>
</html>
MyFrame.html
<html>
<frameset rows="20%,*">
<frame src='college.html'>
<frameset cols="50%,*">
<frame src='logo.html'>
<frame src='course.html'>
</frameset>
</frameset>
</html>
Output:
40. Using tables and Frames Design the following web page:
College Name
Courses
Commerce Science
B.Com. (Eco.) B.Sc.
B.Com. (Computer) B.Sc. (Electronics)
B.Com. (Res.)
To create the given page, we use <frameset>, <frame> and <table> tags. We need to
create three different HTML files 1) To display college name (college.html), 2) Course
Details (course.html) and 3) A page with two horizontal frames (myframe.html). The
programs are shown below. Finally, we need to view “myframe.html” in a browser.
College.html
<html>
<body>
<CENTER> <h4> College Name :</h4>
<h4> APOORVA DEGREE COLLEGE </h4> </CENTER>
</body>
</html>
Course.html
<body>
<CENTER> <h4> COURSES </h4> </CENTER>
<table border=1 width=300>
<tr>
<th> Commerce </th>
<th> Science </th>
</tr>
<tr>
<td> B.Com (Eco.) </td>
<td> B.Sc. </td>
</tr>
<tr>
B- Com III – Web Programming
40 Apoorva Publishers
<td> B.Com (Computer) </td>
<td> B.Sc. (Electronics) </td>
</tr>
<tr>
<td> B.Com (Res.) </td>
<td> </td>
</tr>
</table>
</body>
</html>
MyFrame.html
<html>
<frameset rows="20%,*">
<frame src='college.html'>
<frame src='course.html'>
</frameset>
</html>
Output:
Inline or “floating” frame is the one, which appear on a page like an ordinary element
such as tables or images. Using an inline frame, we can display a html page within
some other html page. The tag used for inline frames is <iframe>. The attributes of this
tag are listed below.
src: This allows us to specify the URL of the document in the frame.
width: This allows us to specify the frame’s length, in pixels.
height: This allows us to specify the frame’s height, in pixels.
frameborder: This allows us to give the frame a border.
Name: This is to set the name of the frame
Output:
<html>
<body bgcolor=green>
<center>
<h1> INLINE FRAMES </H1>
<iframe src='a1.html' frameborder=1>
</iframe>
</center>
</body>
</html>
42. Write the difference between a table and frame. Write a program to print the
different courses offered by an educational institutions using table.
Frame: Frames enable us to present multiple HTML documents within the same
window. For example, we can have a left frame for navigation and a right frame for the
main content. Frames are achieved by creating a frameset page, and defining each
frame from within that page. This frameset page doesn't actually contain any content -
just a reference to each frame. The HTML <frame> tag is used to specify each frame
within the frameset. All frame tags are nested with a frameset tag.
<body>
<center> <h4> COURSES </h4> </center>
<table border=1 width=350>
<tr>
<th> Commerce </th>
<th> Science </th>
</tr>
<tr>
<td> B.Com (Economics) </td>
<td> B.Sc. (Stats) </td>
Output:
<HR> tag: The <hr> tag creates a horizontal line in an HTML page. The hr element can
be used to separate content in an HTML page. It is an empty i.e. has no closing. The
common attributes of <HR> tag are listed below.
<SPACER> tag: The HTML <SPACER> tag is used to create a block of white space within
an html document. This is valid in Netscape browser. The common attributes
supported by this tag are:
<BANNER> tag: Banner tag directs the browser to render the banner graphics/text
unmovable while the user scrolls the remainder of the content. The banner text is
delimited by the tags <banner> and </banner>. The Banner tag is the first tag after the
Body tag, before any text or other HTML coding. If the Banner Tag works, the image
and text should always be visible as we scroll down the page. The common attributes
supported by this tag are:
<LAYER> tag: The HTML <layer> tag is used to position and animate (through scripting)
elements in a page. A layer can be thought of as a separate document that resides on
top of the main one, all existing within one window. This tag has support in Netscape
browsers. The common attributes supported by this tag are:
left/ top: The LEFT and TOP parameters specify the horizontal and
vertical positions of the top-left corner of the layer.
bgcolor Specifies the background color of the layer.
width/ height The width and height parameter determine the width and
height of the layer at which the layer's contents wrap.
visibility The VISIBILITY parameter determines whether the layer is
visible or not. Possible values are: HIDE, SHOW, INHERIT
44. Explain the tags: <BODY>, <FONT>, <MARQUEE>, <BASEFONT> with minimum 2-3
attributes.
<BODY> tag:
<Font> Tag:
<MARQUEE> tag:
<BASEFONT> tag: This tag specifies a default font-color, font-size, or font-family for all
the text in a document.
45. Explain the tags: <SMALL>, <HEAD>, <MARQUEE>, and <A HREF>.
<SMALL> Tag: Small tag renders the text in small size. This tag is supported in major
browsers. We can use nested <small> tags to produce even smaller size. It supports the
standard attributes but has no specific attributes.
<HEAD> Tag:
46. Explain the tags: <EM>, <CODE>, <VAR>, <ABBR>, <ACRONYM>, and <KBD>.
The given tags are known as logical tags. Logical tag tells how the text is being used.
They indicate the 'type' of content they enclose. They do not determine the display of
the text and the browser is free to determine its display style.
All these tags support standard attributes but have so specific attributes. The
output of these tags may be different in different browsers.
<CODE> tag: This defines computer code i.e. The code can be displayed as it is.
Example: <CODE> for (i=0; i<10; i++)
{printf("%d",i);}</CODE>
The above code will display: for (i=0; i<10; i++) {printf("%d",i);}
<VAR> tag: This defines a variable. A browser can create its own display style for
all variables used in the page.
Example: <VAR> COUNT=1 </VAR> gives COUNT=1
<KBD> tag: This indicates text to be entered by the user. This text is usually
rendered in a different font style where every character has the same width.
Example: Enter <KBD>Q</KBD> to quit
Attribute Description
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
title Specifies extra information about an element
<MARQUEE> tag:
<TABLE> tag:
<BLINK> tag: This tag makes the text blink. This is valid only in few browsers like
Netscape. Example is shown below. This has no specific attributes.
<MULTICOL> tag: This tag is used to create multiple columns of text and lets us control
the size and number of the columns. The <multicol> tag can contain any other HTML
content. This tag is supported in Netscape. The common attributes supported by this
tag are:
Example:
<multicol cols="4" gutter=”15” width=“50”>
Welcome To Apoorva
</multicol>
48. What are the main steps involved in creating a webpage and how does it get
executed? (Or) Explain the procedure to create HTML document.
B- Com III - Web Programming
Apoorva Publishers 47
The main steps involved in creating a web page or listed below.
1. Creating a web page using HTML or other web programming languages
2. Saving the file and previewing (executing) it in a browser
3. Publishing the web page
1. Creating a webpage: To create a web page, we can use simple text editors or GUI
editors like FrontPage or even MS-Word.
If we are using an editor like note pad, we need to write the code using HTML
tags as per the requirement.
If we are using FrontPage, we can place the required elements using drag and
drop methods or using menu options.
2. Saving the file and previewing (executing) in a Browser: When saving a HTML file,
we need to give the file extension as “.htm” or “.html”. To preview a HTML file, we
need to open a browser like Internet Explorer or Netscape navigator and type in
the file name in its location window and press enter key.
3. Publishing the webpage: Publishing becomes very easy using tools like Front Page.
This involves uploading the webpage to a hosting server and be able to access it
through www.
Adding images to a HTML page is a common practice today. But, when adding images,
we need to understand the characteristics of images so that we can minimize their
loading time when they are accessed. The following are some important characteristics
of web images.
Details: Good choices of background color, headers, footers, and appropriate font
size are all important details to be considered. Carefully prepared pages help to
enhance the credibility and readability of the presentation.
Coding: A good programmer uses the appropriate elements of style to contribute
to the quality of the presentation. Simplistic pages could indicate lack of
knowledge and cluttered pages indicate poor design.
Features: A few graphic and sound components can improve presentation. For
example, applets, or some Java scripts improve the quality. It is always better to
include too few fancy items.
Graphics: Including graphics is the most significant ways to enhance our design.
Many free images can be found on the Web. It is important to integrate the images
effectively in to presentation.
Layout: If the pages are visually appealing and if they provide convenient
navigation, they are likely to be visited by more users. A poor layout will
discourage people from spending too much time on the presentation.
Writing Quality: Good writing and an interesting style are also necessary for a solid
presentation.
Load time: Users should be taken care not to include too many graphics or any
large graphics. Also users should be given the option to downloading large images
separately.
Hyperlinks: Navigation is a key element to any good Web presentation. If the
reader can move around the pages easily, they will be more impressed. It is always
a good idea to include much navigation.
51. What is the difference between a web page and ordinary file document?
WWW stands for World Wide Web. It is an Internet service developed to incorporate
footnotes, figures and cross-references into online hypertext documents. Hypertext
documents are those in which a user can jump to another location in the same
document or any other document by clicking on some highlighted text. WWW was
created in 1989 at Geneva, Switzerland.
Web page is page of any website that can be accessed through WWW.
A web page can be designed using HTML, ASP, PHP, XML and etc.
Web pages are basically hyper-linked documents that allow non linear reading
Web pages can be dynamic, and they can involve multimedia.
A web page can also be an interface to a database.
54. List common Image File Formats. (or) What are Image File Extensions
A file format is a standardized method of encoding data for storing data. Image files
have the following extensions:
2 VBScript
1. What is VBScript? What are its Features, Advantages and Disdavantages?
2. What is a Data type? What are VBScript Data Types?
3. Distinguish between Client Side Programming and Server Side
Programming with examples.
4. How do you write a VBScript Program? How a VBScript program gets
executed?
5. What is Event Driven Programming?
6. What are Variables? How do you declare variables in VBScript?
7. Explain the Scope and Life of Variables. (Or) What are procedure-level and
Script-level Variables?
8. What are Constants? Explain Constants in VBScript.
9. Explain the Operators in VBScript.
10. Explain Control Structures in VBScript.
11. Explain Branching Control Structures in VBScript.
12. Explain Iterative Control Structures (Loops) in VBScript.
13. Explain Exit Statements in VBScript.
14. Explain With Statement (with/end with) in VBScript.
15. Explain various Functions in VBScript.
16. Explain Math (Number) Functions in VBScript.
17. Explain String (Text) Functions in VBScript.
18. Explain Date and Time Functions in VBScript.
19. Explain Conversion Functions in VBScript.
20. Explain Formatting Functions in VBScript.
21. Explain Logical Functions in VBScript.
22. Explain Miscellaneous Functions in VBScript.
23. Explain Array Functions in VBScript.
24. Write a program to demonstrate Date and Time Functions.
25. Write a program to demonstrate String Functions.
26. Explain String Manipulation Mechanism with an example in VBScript.
27. What are Arrays? How do you declare Arrays in VBScript? (Or) Explain Array
Handling in VBScript.
28. How do you write Comments in VBScript?
Features of VBScript:
It is developed by Microsoft
It is a loosely typed programming language. That is, data-type declaration is not
mandatory.
VBScript programs are interpreted
It is a light weight programming language
It has only one data type called ‘variant’; all other sub data types are compatible
with this.
It is derived from Visual Basic
This is the default scripting language for ASP.
It can be used for both client-side and server-side scripting.
It can be used on IIS (Internet Information Server) to enhance the functionality of
server side applications.
VBScript uses the Component Object Model
VBScript is case-insensitive language
Advantages of VBScript
No installation required. This is readily available with windows operating systems.
Better support through MSDN
VBScript can be directly embedded in HTML documents
Built-in support for COM Automation and WSH (Windows Script Host)
Simple to learn because it is derived from Visual Basic
It allows event driven programming.
It can be used for both client-side and server-side scripting.
Disadvantages of VBScript
Limited third-party modules/add-ons
No command-line code execution support
Not supported by all the browsers
VBScript Data Types: VBScript has only one data type called a Variant. A Variant is a
special kind of data type that can contain different kinds of information, depending on
how it is used. Because Variant is the only data type in VBScript, it is also the data type
returned by all functions in VBScript. A Variant can contain either numeric or string
information. A Variant behaves as a number when we use it in a numeric context and
as a string when we use it in a string context.
Subtype Description
Empty Variant is uninitialized. Value is 0 for numerals or a zero-length string
("") for strings
Null Variant intentionally contains no valid data
Boolean Contains either True or False
Byte Contains integer in the range 0 to 255
Integer Contains integer in the range -32,768 to 32,767
Currency Contains currency
Long Contains long integer
Single Contains a single-precision, floating-point number
Double Contains a double-precision, floating-point number
Date Contains a number that represents a date between January 1, 100 to
(Time) December 31, 9999
String Contains a variable-length string that can be up to approximately 2
billion characters in length.
Object Contains an object.
Error Contains an error number.
3. Distinguish between Client Side Programming and Server Side Programming with
examples.
1. Client-side programming: Client side programming is some code that runs in the
web browser on the user’s computer. An example of client-side programming is
JavaScript. Client-side code is embedded within the web page. By including code
within a web page, a number of features can be added to a web page without
Advantages:
HTML, JavaScript, Flash files, ActiveX controls, Java applets, and a number of
other technologies can be executed on the client side.
They get executed faster.
Client-side scripts have greater access to the information and functions
available on the user's browser.
Client-side scripts do not require additional software on the server.
They reduce burden on servers
Disadvantages:
Client-side scripts may be restricted from executing by the operating system
or web browsers.
A client-side script is plain text embedded in HTML documents. Anyone can
easily view the code.
They require the support of web browsers without which they cannot
function.
Program: The following program is simple example for client side programming
that uses VBScript. It prints the given name when the button is clicked.
<script language="VBScript">
sub B1_OnClick()
document.write ("Hello " & frm.t1.value)
end sub
</script>
<form name="frm" >
Name: <input type="text" name="t1" > <BR>
<input type="button" value="OK" name="B1">
</form>
2. Server-side programming: Server-side programming is some code that runs on the
web-server where the website is located. The resulting code is sent to the browser
(client) and displayed. Server-side programming can be encrypted when users send
B- Com III – Web Programming
56 Apoorva Publishers
form variables, ensuring more security. Some examples of server-side
programming languages are ASP, C#, VB.NET, and PHP.
Advantages:
Server-side scripting does not have any browser limitations.
It can produce the output irrespective of browsers.
Server-side scripts are more secure than client-side because it can use
encryption.
Server-side scripts have greater access to the information and functions
available on the server.
Disadvantages:
Server-side scripts require that their language's interpreter be installed on the
server.
They create burden on the server resulting more network traffic.
Program: The following program is simple example for server side programming
that uses ASP. The HTML file submits the name value to the server-file which in
turn directs the output to browser.
Test.asp
<%
response.write ("Hello " & _
request.querystring("t1"))
%>
Test.html
<form name="frm"
action="http://localhost/myprg/test.asp">
Name: <input type="text" name="t1" > <BR>
<input type="submit" name="submit">
</form>
4. How do you write a VBScript Program (Structure)? How a VBScript program gets
executed?
A VBScript program can be written in three different ways as shown below:
1. Embedding the script in <BODY> tag: To embed the code in HTML file, we need to
use <SCRIPT> tag. Script tag allows specifying the scripting language used; Here,
the ‘langauge’ should be ‘VBScript’. The following program shows using script in
body tag.
<html>
<body>
<script language="VBScript">
document.write("Welcome to VBScript")
</script>
</body>
</html>
2. Embedding the script in <HEAD> tag: Embedding the script in <HEAD> tag is more
common than it is in <body> tag. We can also write procedures or functions that
can be invoked when an associated event triggers. There are a number of events
that will trigger the execution of a VBScript, like clicking on a form button, or when
the web page is loaded. The following program shows using script in head tag.
<html>
<head>
<script language="VBScript">
document.write("Welcome to VBScript")
</script>
</head>
<body>
<br> Welcome to Apoorva
</body>
</html>
3. Writing an external file and linking it in HTML: When the code is lengthy and has
more number of programs, it is a good idea to write it in a separate file for which
the extension should be “.vbs”. We, then include it in the HTML document by
specifying it in ‘src’ attribute of <script> tag. The following program shows
including script file.
First prepare a .vbs file by writing the required script code in that. Example is
shown below.
Code in “s1.vbs”:
B- Com III – Web Programming
58 Apoorva Publishers
Msgbox "I am invoked through external file"
Now, write the HTML file and specify the script file in ‘src’ attribute of script tag.
<html>
<head>
<script Language="VBScript" src="s1.vbs">
</script>
</head>
<body onload="f1">
Demo using External Script file
</body>
</html>
Events are various actions that take place in a program. Script can be invoked
when an associated event triggers. VBScript allows for event driven programming.
A function or procedure will be executed only when the associated event triggers.
Events can be triggered by performing specified action on different form elements
or HTML elements such as buttons, checkboxes, radio buttons, form, table and so
on.
Each element may support several different events. For example, The <body> tag
supports the events like onclick, onload, onunload, onmousedown an etc.
Variable: Variable is a named storage location that can contain data i.e. it is a
placeholder of a value. VBScript does not demand variable declaration; because it is a
loosely typed programming language Each variable has a name that uniquely identifies
it within its level of scope. The following are the rules for giving Variable names:
Must begin with an alphabetic character.
Can't contain an embedded period or special characters (except underscore)
Must be unique within the same scope.
Must be no longer than 255 characters.
Cannot include spaces
A special character underscore ( _ ) can be used
Declaring Variables: There are many ways of declaring variables. The different ways of
declaring variables in VBScript are:
1. Implicit Declaration
2. Explicit Declaration
Example:
<html>
<body>
<script language="VBScript">
x=30
y=40
msgbox "sum=" & (x+y)
</script>
</body>
</html>
Example:
<script language="VBScript">
private y
public z
Sub f1()
dim x
x=30
y=40
z=50
msgbox "sum = " & (x+y+z)
end sub
</script>
<body onload="f1">
</body>
Example:
<html>
<body>
<script language="VBScript">
option explicit
dim x,y ‘declaration is compulsory here
x=30
y=40
msgbox "sum=" & (x+y)
</script>
</body>
</html>
7. Explain the Scope and Life of Variables. (Or) What are procedure-level and Script-level
Variables?
SCOPE and LIFE of Variables: Scope and Life of variables is determined by the location
where they are declared i.e. whether they are procedural-level or script-level.
Script-level: If a variable is declared in the script section (outside the procedures),
it is called a script-level variable and the scope of this type of variable is in all the
procedures; and the life is until the script finishes its execution.
procedure-level: If a variable is declared within the procedure, it is called a
procedure-level variable and the scope of this type of variable is within that
procedures; and the life is until the control comes out of that procedure.
Example:
<script language="VBScript">
Dim x ‘script-level varibale
X=40
Sub f1()
Dim y ‘procedure-level varibale
End sub
Sub f2()
z=x ‘we can access ‘x’throughout the script
End sub
</script>
2. Explicit Constants: These are defined by the user in a program. These constants
can be assigned to any variable in VBScript without declaring the type. Following
are different types of explicit constants.
Integer constants: There are three types of integers, namely, decimal, octal
and hexadecimal integers. Ex: 30, 40, 1e (hex).
Float constants: They are whole numbers followed by a decimal point and
fractional part. They may be expressed in scientific (exponential) notation. Ex:
3.14, x=0.64e4
String/Char constants: VBScript treats character and string constants same.
Strings must be enclosed in double quotes. Ex: “kiran”, “1234”
Boolean (logical) constants: Boolean constants are true and false.
Date constants: These values indicate date and time values. Date and time
literals are represented by enclosing them in number signs (#). Ex:
#12/7/2000#
Arithmetic Operators:
Comparison Operators:
Logical Operators:
Other Operators:
VBScript provides several types of control structure. They control the execution order
and number of times a block of statements gets executed etc. The types are given
below.
1. Branching (Conditional) Control Structures
2. Iterative Control Structures (loops)
3. Exit statements
If … Then … End If
If … Then … Else … End If
If … Then … ElseIf … End If
Select Case … End Select
If … Then … End If: The If...Then structure performs an indicated action only when the
condition is True; otherwise the action is skipped. If...Then statements can use either
single-line or multiple-line syntax.
Single line:
If condition Then statement
Multiple line:
If condition Then
statements
End If
The statements are executed only when the condition is true. The condition is usually a
comparison. In the single-line version End If statement is not used. It is used to execute
only one statement based on a condition. The multiple-line version can execute one or
more statements. The following program demonstrates If Then Structure:
B- Com III – Web Programming
64 Apoorva Publishers
<script language="VBScript">
age=25
if age>22 then
document.write "Get Ready for Marriage"
end if
</script>
If … Then … Else … End If: An If...Then... Else block allows us to define two blocks of
code. “then” block gets executed when the condition is true and “else” block gets
executed when the condition is false.
If condition Then
statements
Else
statements
End If
The following program uses if then else to find out whether the number is even or odd
<script language="VBScript">
x=4
If x Mod 2 = 0 Then
document.write "even"
Else
document.write "odd"
End If
</script>
If condition Then
Statements
Elself condition2 Then
Statements
Else
Statements
End If
The following program uses if then elseif structure
<script language="VBScript">
x=MsgBox("Are U OK?", vbYesNoCancel, "Message")
If x=vbYes Then
Select Case … End Select: Select Case structures are similar to If...Then...Elself
structures. They allow the program to choose from more than two alternatives. In
other words, the result of the testexpression is compared against multiple values to
determine which code block should be invoked. The syntax is shown below.
<script language="VBScript">
i=MsgBox("Are U OK?",vbYesNoCancel,"Message")
Select Case i
Case vbYes
MsgBox "Yes is selected"
Case vbNo
MsgBox "No is selected"
Case Else
MsgBox "Cancel is selected"
End Select
</script>
Do While/Loop, Do/Loop While: These loops execute the statements until the given
condition becomes false. Do While/Loop structures check the condition before
executing the code. Do/Loop While structures executes the code and then check the
condition.
Do Until/Loop, Do/ Loop Until: These loops execute the statements until the condition
becomes true. Do Until/Loop structures check the condition before executing the code.
Do/Loop Until structures executes the code and then check the condition.
Do-Loops syntaxes are shown below.
Do While/Until condition
Statements
Loop
Do
Statements
Loop While/Until condition
The following program uses “Do While/Loop” to print the given message 10 times
<script language="VBScript">
x=0
Do While x <10
document.write "<BR> To Be or Not to be"
x=x+1
Loop
</script>
The following program uses “Do Loop/Until” to print the given message 10 times
<script language="VBScript">
x = 0
Do
document.write "<BR> Just Do it"
x=x+1
Loop Until x=10
</script>
While condition
Statements
Wend
<script language="VBScript">
x=0
While x <10
document.write "<BR> Great Job"
x=x+1
Wend
</script>
For ... Next, For Each ... Next: The For...Next Loop is another way to make loops in
VBScript. The For...Next statement executes a code block a specific number of times.
The counter value in a For.... Next structure can either increase or decrease depending
on whether step is positive or negative. For Each…Next refers to each member of the
array or collection. The Syntax for both are shown below.
<script language="VBScript">
For k = 2 To 10 step 2
document.write "<br>" & k
Next
</script>
The following program uses “for each” to print the elements of the array
<script language="VBScript">
x = Array(10, 20, 30)
B- Com III – Web Programming
68 Apoorva Publishers
For Each k In x
document.write "<br>" & k
Next
</script>
Exit Statements: VBScript also provides exit statements to bring out the control from
loops or sub-procedures or function procedures.
Exit Do
Exit For
Exit Sub
Exit Function
Exit Do: “Exit Do” makes the control quit the corresponding Do Loop and continues
with the remaining part of the program.
Exit For: “Exit For” makes the control quit the corresponding For Loop and continues
with the remaining part of the program.
The following program uses “exit for” and prints “Hello” for 5 times only.
<script language="VBScript">
For x = 1 To 10
Document.write "<br> Hello"
x = x + 1
If x = 5 Then Exit For
Next
</script>
Exit Sub: “Exit Sub” makes the control quit the corresponding Subroutine and returns
to the point from where the function is called. The following program prints “Hello”
and “Everybody”.
<script language="VBScript">
Display
Sub Display()
Document.write "Hello"
Exit Sub
Document.write "World"
End Sub
</script>
Exit Function: “Exit Function” makes the control quits the corresponding Function and
returns to the point from where the function is called. The following program
demonstrates “Exit Function”
B- Com III - Web Programming
Apoorva Publishers 69
<script language="VBScript">
Document.write GetRoot(16)‘prints 4
Document.write GetRoot(-9)‘doesn’t print anything
Function GetRoot(x)
If x < 0 Then Exit Function
GetRoot = Sqr(x)
End Function
</script>
Syntax:
With object
statements
End With
Example: The following program illustrates use of the With statement to assign values
to several properties (title, bgcolor, fgcolor, and write) of the object ‘document’.
<script language="VBScript">
with document
.title = "with demo"
.bgcolor = "yellow"
.fgcolor = "blue"
.write ("Hello Apoorva")
end with
</script>
There are many predefined functions in VBScript. They enhance the functionality of the
scripts. Following are the different categories of predefined (built-in) functions.
1. Math (Number) Functions
2. String (Text) Functions
3. Date and Time Functions
4. Conversion Functions
B- Com III – Web Programming
70 Apoorva Publishers
5. Formatting Functions
6. Logical Functions
7. Miscellaneous Functions
8. Array Functions
In Conversion functions, there are two types: 1) Value Conversion functions and 2)
Type Conversion (data type conversion) functions.
Function Description
CreateObject Creates an object of a specified type
GetObject Returns a reference to an automation object from a file
GetRef Allows us to connect a VBScript procedure to a DHTML event on our pages
An array is a set of values of similar type. To work with arrays, VBScript provides several
built in functions: Array, IsArray, Join, Filter, Split, UBound, and LBound. The functions
are explained below.
1. Array: Array function allows us to define the array. Each individual element can
access the array element using an index, which starts from ‘zero’. The following
program demonstrates defining an array using ‘Array’ function.
<script language="VBScript">
s= Array("Rama", "Arun", "Amar", "Kiran")
For i = 0 To 3
document.write " " & s(i)
next
</script>
<script language="VBScript">
s= Array("Rama", "Arun", "Amar", "Kiran")
document.write IsArray(s)
</script>
Output: True
<script language="VBScript">
Dim MyArray(4)
MyArray(0) = "Apoorva"
MyArray(1) = "Degree"
MyArray(2) = "College"
str= Join(MyArray)
document.write str
</script>
Output: ApoorvaDegreeCollege
4. Filter: Filter function returns an array containing subset of a string array based on
specified filter criteria. The following example uses the Filter function to return the
array containing the search criteria "Mon":
<script language="VBScript">
Dim MyArray (3)
MyArray(0) = "Sunday"
MyArray(1) = "Monday"
MyArray(2) = "Tuesday"
str = Filter(MyArray, "Mon")
document.write str(0)
</script>
Output: Monday
5. Split: Split function returns one-dimensional array containing a specified number
of substrings. Here, we can use a delimiting character that can be used to identify
substring limits. The following example splits a string into an array of substrings
<script language="VBScript">
str = Split("VBScript-is-fun!", "-")
document.write str(0)
</script>
' str(0) contains "VBScript”
' str(1) contains "is"
' str(2) contains "fun!"
Output: VBScript
Output: UBound = 3
LBound = 0
Program:
<script language="VBScript">
document.write "<BR>Date and Time : " & Now
document.write "<BR>Date : " & Date
document.write "<BR>Time : " & Time
document.write "<BR>Year part : " & Year(Now)
document.write "<BR>Month part : " & Month(Now)
document.write "<BR>Hour part " & Hour(Now)
document.write "<BR>Difference between the dates : " & _
DateDiff("d", "10/7/1999", "10/15/1999")
document.write "<BR>Date after adding 5 days : " & _
DateAdd("d", 5, #10/7/1999#)
document.write "<BR>Day of the Date : " & _
DatePart("d", #10/7/1999#)
document.write "<BR>Formating date : " & _
FormatDateTime("10/3/1999",1)
</script>
Output:
Date and Time : 11/22/2010 9:44:39 PM
Date : 11/22/2010
Time : 9:44:39 PM
Year part : 2010
Month part : 11
Hour part 21
Difference between the dates : 8
Date after adding 5 days : 10/12/1999
Day of the Date : 7
Formating date : Sunday, October 03, 1999
Program:
<script language="VBScript">
document.write "<BR>" & StrComp("AB", "AB")
document.write "<BR>" & StrReverse ("RAMA")
document.write "<BR>" & Left("APOORVA", 2)
document.write "<BR>" & Right("ABCD",2)
document.write "<BR>" & Mid("VARMA",2, 3)
document.write "<BR>" & String(3, "$")
document.write "<BR>" & InStr(1, "This is", "is")
document.write "<BR>" & InStrRev("This is", "is",7)
document.write "<BR>" & "A" & Space(3) & "B"
document.write "<BR>" & UCase("apple")
document.write "<BR>" & LCase("APPLE")
document.write "<BR>" & Trim(" ABC ")
document.write "<BR>" & LTrim(" ABC")
document.write "<BR>" & RTrim("ABC ")
document.write "<BR>" & Len("APOORVA")
document.write "<BR>" & Replace("ABXYAB", "AB", "UV")
</script>
Output:
0
AMAR
AP
CD
ARM
$$$
3
6
A B
APPLE
apple
ABC
ABC
ABC
7
UVXYUV
String Functions:
Note: Refer to Question No: 17 in this chapter
27. What are Arrays? How do you declare Arrays in VBScript? (Or) Explain Array Handling
in VBScript.
1. Using Dim Statement: Using this method, we first specify the size of the array and
have the elements later in the program. Array is supported by many functions like
“join”, “filter”, “split”, “uboud”, “lbound” and etc. For example, “ubound” function
gives the upper limit of the array. Following example demonstrates defining array
using “dim” statement.
<script language="VBScript">
dim a(10)
a(0)="Ramu"
a(1)="Arun"
a(2)="Kiran"
a(3)="Pavan"
for i=0 to 3
document.write(a(i) & "<br>")
next
</script>
2. Using “Array()” Function: We use this when we want to give the values, while
defining the array itself. Even this kind of array supports all the array functions.
Following example demonstrates defining array using “Array()” function
B- Com III – Web Programming
80 Apoorva Publishers
<script language="VBScript">
a=Array(10,20,30,40)
for i=0 to 3
document.write(a(i) & "<br>")
next
</script>
It is common practice to use for-each loop to print the array elements as shown
below. Here, ‘x’ refers to each element of the array and we don’t use indexes when
using for-each.
<script language="VBScript">
a=Array(10,20,30,40)
for each x in a
document.write(x & "<br>")
next
</script>
1. ' comment: This allows single line commenting. This can be written in a
separate line or alongside of a statement.
2. REM comment: Even this allows single line commenting. This requires a colon (:)
When it is written alongside of the code line; But, if REM comment is written in a
separate line colon is not needed. REM comment also requires a space between
REM and comment.
<script language="VBScript">
Dim MyStr1, MyStr2
MyStr1 = "Hello" : Rem comment separated by a colon
MyStr2 = "Apoorva" ' This is also a comment
Rem This is also a comment but without a colon
</script>
1. SUB PROCEDURES: It is a reusable block of statements that does not return any
value. A sub procedure can be placed in a <sript> tag set. Each time the procedure
is called, the statements between Sub and End Sub are executed. The syntax for a
sub procedure is as follows:
sub procedurename(arg-list)
Statements
End Sub
<script language="VBScript">
SayHello 'calling a procedure
Sub SayHello()
document.write "Hello from a function"
end sub
</script>
<script language="VBScript">
sum 30,40 'calling a procedure with arguments
call sum(80,90)'another way of calling a procedure
Sub sum(x,y)
document.write "<BR> Sum= " & (x+y)
end sub
</script>
B- Com III – Web Programming
82 Apoorva Publishers
2. FUNCTION PROCEDURES: Functions are like sub procedures, except that they
return a value to the calling procedure. The default value returned by a Function
procedure is a Variant. The syntax for a function procedure is as follows:
Example: The following program uses a function that returns the factorial of a
given number.
<script language="VBScript">
document.write "Factorial of 4=" & Fact (4)
Function Fact (X)
F=1
For I=1 to X
F=F*I
Next
Fact=F
End Function
</script>
33. What are VBScript Dialog Boxes? (Or) Explain MsgBox and InputBox with examples.
Dialog Boxes: Dialog Boxes are used to display information to or retrieve information
from the user. They ask the user for the data needed to continue an application. Dialog
Boxes are either Modal or non-Modal. A Modal Dialog Box does not allow the user to
continue with other applications unless it is closed or unloaded. The non-Modal dialog
1. MSGBOX: Displays a message in a dialog box, waits for the user to click a button,
and returns a value indicating which button the user clicked. The syntax of the
function, its arguments are shown below.
Example: The following example illustrates the use of the MsgBox function.
<script language="VBScript">
result = MsgBox ("Did U Like
VBScript?",vbYesNoCancel+vbQuestion, "My Question")
Select Case result
Case vbYes
Document.write "That’s nice. Go On exploring"
Case vbNo
Document.write "Concentrate More"
Case vbCancel
Document.write "U didn’t answer me"
End Select
</script>
2. INPUTBOX: Displays a prompt in a dialog box, waits for the user to input text or
click a button, and returns the contents of the text box.
Arguments:
Prompt: String displayed as the message in the dialog box.
Title: String displayed in the title bar of the dialog box.
default: A default value displayed in the text box if the input is not
provided.
ypos: x-position of the dialog box
ypos: x-position of the dialog box
Helpfile: A String that identifies the Help file
Context: A Number that identifies the Help context number
Example: The following example uses the InputBox function to display an input box and
assign the string to the variable ‘str’
<script language="VBScript">
str = InputBox("Enter your name")
MsgBox ("Nice to meet you " & str)
</script>
34. What are the different user interaction elements present in VB script? (Or) How user
interaction can be achieved in VBScript? (Or) What is User Interaction? Write a
program to show how it can be performed using VBScript.
User Interaction is the ability of the user to work with the web page i.e. clicking the
buttons, entering values, changing the size, and etc. User interaction in VBScript can be
achieved through 1) VBScript’s own elements (dialog boxes) 2) HTML elements (like
buttons, text fields, and so on) combined with events.
1) VBScript’s own elements (dialog boxes): VBScript provides two elements for the
user interaction. They are
a) Msgbox:
Note: refer to section 1(Msgbox) in the previous question.
b) Inputbox:
Note: refer to section 2(Inputbox) in the previous question.
B- Com III - Web Programming
Apoorva Publishers 85
2) HTML elements with events: HTML elements include many graphical user
interfacing elements. Each of these elements can be associated with one more
events. If an event is triggered the related procedure will be executed. The
different elements are shown below.
Element Description
Text A single-line text input control
Textarea A multi-line text input control
Password A password input control
Label A label for an input element
Checkbox A checkbox that can be checked or unchecked
Radio A group of options in which only one can be selected
Button A push button that can be clicked to perform an action
Select A drop-down list control
Submit A button that sends information to server when clicked
Reset A button that clears form elements’ information
Events: Some of the common events that are supported by most of the above
controls are listed below.
Events Meaning
onclick When a mouseclick happens on an element
ondblclick When a mouse-doubleclick happens on an element
onblur When an element loses focus
onfocus When an element gets focus
onkeydown When a keyboard key is pressed
onkeyup When a key is released
onkeypress When a keyboard key is pressed or held down
onmousedown When a mouse button is held down
onmouseup When mouse button is released
onmousemove When mouse moves
onmouseout When muse cursor is moved out of the control
onmouseover When mouse moves over the control
Example: The following program uses a button control with onclick() event.
<script language="VBScript">
sub B1_OnClick()
msgbox "U Clicked Me"
end sub
</script>
<body>
<form>
B- Com III – Web Programming
86 Apoorva Publishers
<input type=button value="Click Me" name="B1">
</form>
</body>
The above program displays a button and it gives a message through msgbox
when we click on that.
35. Write a program to display a message box while clicking on the button using VB script.
HTML is capable of producing only static pages i.e. the information that it shows in a
page cannot be user-specific and it cannot facilitate user interaction. But, dynamic
content can very well facilitate user interaction or the pages can be made user-specific
and time-specific or it allows the users to set their own settings to view pages.
For example, a page may recognize the user and greet him with his name or it may ask
the user to fill in information and perform validity or calculations on it.
To design a web site with dynamic content, we need a set of technologies like HTML,
CSS, JavaScript/VBScript, XML and etc.
Example: Following is a simple program that displays running time like a digital clock
i.e. the time value in the page changes automatically as the time changes.
<script language="VBScript">
sub f1()
head1.innerHtML = time
end sub
set t=setInterval("f1()",1000)
</script>
<body>
<h1 id="head1"> </h1>
</body>
B- Com III - Web Programming
Apoorva Publishers 87
37. What are Run-Time Errors in VBScript? (Or) What are different types of errors?
The two different types of errors present in a program are: 1) Syntactical errors and 2)
Run-time errors.
1. Syntactical errors: These errors do not allow the execution of the program. They
violate the syntax of different constructs of a program. For example, missing a semi
colon, unterminated string, object expected are some of syntactical errors.
2. Runtime errors: VBScript run-time errors are errors that result when some script
attempts to perform an action that the system cannot execute. VBScript run-time
errors occur while the script is being executed or when variable expressions are
being evaluated or when memory is dynamically allocated. When runtime error
occurs, a program will be terminated abruptly i.e. the program stops from being
executed. To avoid this, we use Error handling. The following program raises a
runtime error called ‘Division by zero’ when y (denominator) value is ‘zero’.
Otherwise, it will be executed normally.
<script language="VBScript">
x=inputbox("Enter x value")
y=inputbox("Enter y value")
document.write "Div = " & (x/y)
document.write "<br>Thank you"
</script>
Some of the common run time errors in VBScript are listed below. Every runtime error
is associated with a number. For example, the number for ‘Division by zero’ is 11.
38. Explain Error Handling in VBScript. (Or) Explain Handling runtime Errors in VBScript.
When a runtime error occurs, a program will be terminated abruptly i.e. the program
stops from being executed. To avoid this, we use Error handling.
Error handling: Error handling is a mechanism to handle runtime errors. Error handling
enables programmers to write error-free programs. Proper error handling ensures safe
termination of a program. We use ‘on error resume next’ statement to handle runtime
errors in VBScript.
This statement enables an error trap and moves the control to the next statement to
the statement that caused error. This is where error handling is written.
<script language="VBScript">
On Error resume next
x=inputbox("Enter x value")
y=inputbox("Enter y value")
document.write "Div = " & (x/y)
if err.number = 11 then
document.write "Denominator cannot be a zero"
end if
document.write "<br>Thank you"
</script>
39. What is Err Object? What are its Properties and Methods?
Example: Following program demonstrates the use of ‘Err’ object and its properties
and methods.
<script language="VBScript">
On Error resume next
x=8
y=0
document.write "Div = " & (x/y)
if err.number <> 0 then
document.write "Number: " & err.number
document.write "<br>Description:" & err.description
document.write "<br>Source: " & err.source
err.clear
end if
</script>
40. What is Data Validation (Form Validation)? Write a program to show how data
validation is performed using VB Script. (Or) Write notes on Data Validation.
Data type validation: Whether the data-type of the value matches with the one
required or not. For example, name cannot be a number.
Value Validation: Whether the value is in a required format or not. For example, e-
mail id should have proper format.
Range checking: whether the value is within the expected range or not. For
example, Marks cannot be less than ‘0’ or greater than ‘100’.
Data Existence: whether the given value exists or not. For example, course exists in
a college or not.
Example: The program given below performs the following data validations.
1. Name should contain only letters (it should not contain digits and special
characters)
2. Rno should be numeric
3. Date-of-Birth should be a valid date.
The program when executed, will not allow invalid values for the said fields. In the case
of invalid data it gives a message and stays in the same page to facilitate re-entry of
data i.e. it will not submit the data to the server. If and only if all the fields have valid
data, they will be submitted to server.
<script language="VBScript">
function frm_OnSubmit()
dim val
val=true
s1=trim(frm.t1.value)
s2=trim(frm.t2.value)
s3=trim(frm.t3.value)
function isWord(s)
for i=1 to len(s)
v= asc(mid(s,i,1))
if v<65 or v>122 or (v>90 and v<97) then
isWord=false
exit function
end if
next
isWord=true
end function
</script>
<body>
<form name="frm" action="test.asp">
Name: <input type="text" name="t1" > <BR>
R.No : <input type="text" name="t2" > <BR>
DOB : <input type="text" name="t3" > <BR>
<input type="submit" name="Submit Form" value="Submit Form">
<input type="reset" value="Clear Form">
</form>
</body>
41. Write a program of Student Registration form using VB script. Write necessary
validations.
The following program displays a student registration form and performs data
validation on the following fields.
1. Name should contain only letters (it should not contain digits and special
characters)
2. Date-of-Birth should be a valid date.
3. City should contain only letters
4. Pin should be numeric and should have six digits.
B- Com III – Web Programming
92 Apoorva Publishers
The program when executed, will not allow invalid values for the said fields. In the case
of invalid data it gives error messages within the page and stays in the same page to
facilitate re-entry of data i.e. it will not submit the data to the server. If and only if all
the fields have valid data, they will be submitted to server.
<script language="VBScript">
function frm_OnSubmit()
dim val
NameERR.innerHTML=""
CityERR.innerHTML=""
PinERR.innerHTML=""
DobERR.innerHTML=""
s1=trim(frm.sname.value)
s2=trim(frm.city.value)
s3=trim(frm.pin.value)
s4=trim(frm.dob.value)
val=true
if s1="" or not isWord(s1) then
NameERR.innerHTML="Invalid Name"
val=false
end if
function isWord(s)
for i=1 to len(s)
v= asc(mid(s,i,1))
if v<65 or v>122 or (v>90 and v<97) then
isWord=false
exit function
end if
next
isWord=true
end function
</script>
<body>
<center>
<h2> College Registration Form </h2>
<form name="frm" action="test.asp">
<tr>
<td>Date of Birth: </td>
<td><input type="text" name="dob">
<span id="DobERR" style="color:red"></span></td>
</tr>
<tr>
<td>Course: </td>
<td><select name="course">
<option value="BSc">BSc</option>
<option value="BCom">BCom</option>
<option value="BBM">BBM</option>
<option value="BA">BA</option>
</select> </td>
</tr>
<tr>
<td>City: </td>
<td><input type="text" name="city">
<span id="CityERR" style="color:red"></span></td>
<tr>
<td>Pin: </td>
<td><input type="text" name="pin">
<span id="PinERR" style="color:red"></span></td>
</tr>
</table>
<br>
<input type="submit" name="Submit Form" value="Submit Form">
<input type="reset" value="Clear Form">
</form>
</center>
</body>
42. Using VBScript, Design a webpage of Student Registration form for a Computer
Institute.
Note: Refer to the above program. Do the necessary changes to “course” field i.e. the
options for this field can be “c”, “c++”, “java”, “oracle” and etc.
<script language="VBScript">
sub B1_OnClick()
x = int(frm.t1.Value)
y = int(frm.t2.Value)
document.write "<h1>Sum = " & (x+y) & "</h1>"
end sub
</script>
<body>
<form name="frm">
Enter X Value: <input type=text name="t1"> <br>
Enter Y Value: <input type=text name="t2"> <br>
44. What are Script engines and how they are helpful? Explain.
The script engine implements all the functions and procedures that can be used in
script programs.
Without script engine, we cannot execute our script programs.
Script engines are provided by the operating system itself.
The browser identifies the language of the script, and then calls the appropriate
scripting engine.
There are also built-in methods to identify the script engine type and versions. The
methods are used in the following program.
<script language="VBScript">
document.write(ScriptEngine & "<br>")
document.write(ScriptEngineBuildVersion & "<br>")
document.write(ScriptEngineMajorVersion & "<br>")
document.write(ScriptEngineMinorVersion)
</script>
On the other hand, there exist server-side script engines like the ASP engine. This
is installed on the web server and is responsible for processing ASP scripts. It is the
responsibility of ASP engine to process the ASP scripts and send the results back as
HTML text to the client. The ASP engine also invokes vbscript.dll to run VBScript
scripts.
3 DHTML
1. What is DHTML? What are its Advantages and Disadvantages?
2. Write the difference between HTML and DHTML.
3. Discuss about Cascading Style Sheets (CSS) with example.
4. How many types of style sheets are existing in DHTML? Explain with an
example. (Or) Explain about (i) Style Sheets (ii) External Style Sheets (iii)
Embedded Style Sheets (iv) Inline Style Sheets.
5. Explain Inline Style Sheets with an example.
6. Explain Embedded Style Sheets with an example.
7. Explain External (Linked) Style Sheets with an example.
8. Explain Imported Style Sheets with an example.
9. Explain different types of Selectors used in style sheets.
10. Discuss Style Classes with an Example.
11. Explain Text Properties in CSS (DHTML).
12. Explain Font Properties in CSS (DHTML).
13. Explain Background Properties in CSS (DHTML).
14. Explain Border Properties in CSS (DHTML).
15. Explain Margin Properties in CSS (DHTML).
16. Explain Positioning and Display Properties in CSS (DHTML).
17. Explain Dimension Properties in CSS (DHTML).
18. Explain List Properties in CSS (DHTML).
19. Explain Table Properties in CSS (DHTML).
20. How to position the following elements using style sheet? Write a program
to position three images as shown in the figure below.
21. What is an Event? Explain Event handling in DHTML. (Or) Discuss about
Dynamic HTML Event Model with the help of an example.
22. Write short notes on ONCLICK event with example.
23. Write short notes on ONDBLCLICK event with example.
24. Write short notes on ONMOUSEOVER, ONMOUSEOUT events with an
example.
25. Write short notes on ONMOUSEUP, ONMOUSEDOWN, ONMOUSEMOVE
events with an example.
26. Explain “Mouse events” with examples.
DHTML: DHTML stands for dynamic HTML. DHTML is not a programming or markup
language like HTML. It is a term that is used to describe the creation of dynamic and
interactive pages. One of the advantages of DHTML for web design and clients is that it
can combine the use of HTML, JavaScript/VBScript, XML and CSS (Cascading Style
Sheets).
HTML is capable of producing only static pages i.e. the information that it shows in a
page cannot be user-specific and it cannot facilitate user interaction. But, dynamic
content can very well facilitate user interaction or the pages can be made user-specific
and time-specific or it allows the users to set their own settings to view pages.
For example, a page may recognize the user and greet him with his name or it may ask
the user to fill in information and perform validity or calculations on it.
To design a web site with dynamic content, we need a set of technologies like HTML,
CSS, JavaScript/VBScript, XML etc. This technological integration is nothing but DHTML.
Advantages:
DHTML is more efficient for content management purposes.
A rich set of graphical capabilities can be implemented
Allows for event driven programming
DHTML results in faster and fresher content, which is more visually appealing.
Both content and layouts can be quickly manipulated
DHTML content loads very fast
Support for XML
Supports DOM (Document Object Model)
Disadvantages:
Costly Editing tools: Although DHTML provides great functionality but the DHTML
editors available are expensive. Dreamweaver is an example of HTML editor.
Long and Complex coding: DHTML coding is long and complex.
Browser Support problems: DHTML suffers from browser support problems. For
example, a code written for Netscape might not work in Internet Explorer and vice-
versa.
HTML DHTML
HTML stands for HyperText Markup DHTML stands for Dynamic HTML
CSS: CSS stands for Cascading Style Sheets. Cascading Style Sheet (CSS) is a style sheet
language used to describe the presentation semantics (the look and formatting) of a
document written in a markup language. The common application of CSS is to style web
pages written in HTML and XHTML, but the language can also be applied to any kind of
XML document.
Syntax: CSS has a simple syntax and uses a number of English keywords to specify the
names of various style properties. A style sheet consists of a list of rules. Each rule
consists of one or more selectors and a declaration block. A declaration-block consists
of a list of declarations in braces. Each declaration itself consists of a property, a colon
(:), a value, then a semi-colon (;). The syntax is shown below.
The selector is normally a HTML element or our own class or id we want to style.
Each declaration consists of a property and a value.
The property is the style attribute we want to change. Each property has a value.
Types of properties supported by CSS: The main capabilities of CSS are its support for
the following.
Font properties such as type, size and emphasis
Color of text, backgrounds, and other elements
Text attributes such as spacing between words, letters, and lines of text
Alignment of text, images, tables and other elements
Advantages:
CSS can be made dynamic by using them in Scripts. With a simple change of one
line, a different style sheet can be used for the same page
It facilitates Separation of content from presentation (styles)
Site-wide consistency, the global style sheet can be used to affect and style
elements site-wide.
Bandwidth, a style sheet is stored in the browser cache. Therefore, it can be used
on multiple pages without being reloaded, reducing data transfer over a network.
Disadvantages:
Poor layout controls
There are control limitations to place elements vertically
We cannot use mathematical expressions in the place of values
Lack of column declaration i.e. multiple columns are complex to implement.
Pseudo-class (like :hover, :first-line) dynamic behavior not controllable
Example: The following program uses two HTML element selectors h1 and h2 to apply
styles on them.
<HEAD>
<TITLE>CSS Example</TITLE>
<STYLE TYPE="text/css">
H1 { font-size: x-large; color: red }
H2 { font-size: large; color: blue }
</STYLE>
</HEAD>
<body>
<h1> Hello </h1>
<h2> Apoorva </h2>
</body>
4. How many types of style sheets are existing in DHTML/CSS? Explain with an example.
(Or) Explain about (i) Style Sheets (ii) External Style Sheets (iii) Embedded Style
Sheets (iv) Inline Style Sheets.
Style Sheet: A style sheet is used to describe the presentation semantics (the look and
formatting) of a document written in a markup language. The common application of
CSS is to style web pages written in HTML and XHTML, but the style sheets can also be
applied to any kind of XML document.
Inline styles: These are written inside the HTML document, style information on a
single element, specified using the "style" attribute
The keyword style is followed by a quoted list of style properties and associated values,
connected with colons (:) and separated by semicolons (;). For instance, to set the font
family and font size for the text contained within a paragraph, the following inline style
sheet is coded inside the opening <p> tag.
An inline style sheet can appear inside any tag to directly set its style. All that is
required is to enclose the applicable style properties and values inside the style
attribute.
Embedded Style Sheets: These are written as blocks of CSS information inside the
HTML using <style> tag. When a large number of style settings are used on a Web page,
we can use style settings together in one place as an embedded style sheet. An
embedded style sheet normally is coded inside the <head> section of the document
surrounded by a <style> tag. It applies styles across the entire Web page through
B- Com III – Web Programming
102 Apoorva Publishers
simple selectors, group selectors, contextual selectors, ID selectors, class selectors,
and sub-class selector whose general formats are shown below.
<head>
<style type="text/css">
tag {property:value; ...} /* Simple selector */
tag, tag,... {property:value; ...} /* Group selectors */
tag sub-tag ... {property:value; ...} /* Contextual selector */
#id {property:value; ...} /* Id selector */
.class {property:value; ...} /* Class selector */
tag.class {property:value; ...} /* sub-class Selector */
</style>
</head>
Example: The following program uses two one simple selector ‘h1’ and a class selector
“mystyle” to apply styling. Here, we have embedded the style definitions in the HTML
program using <style> tag.
<HEAD>
<TITLE>CSS Example</TITLE>
<STYLE TYPE="text/css">
h1 { font-size: x-large; color: red }
mystyle { font-size: large; color: blue }
</STYLE>
</HEAD>
<body>
<h1> Hello </h1>
<h2 class="mystyle"> Apoorva </h2>
</body>
External (Linked) Style Sheets: These are separate “.CSS” files referenced from the
document. The format for defining linked styles is the same as for an embedded style
sheet with the exception that a <style> tag does not enclose the specifications. The
style sheet document is saved as a simple text file, normally identified with the .css file
extension to differentiate it from .html documents.
For example, below is a set of style specifications contained within a text document
named “mysheet.css”
Any HTML page can apply these style settings by linking to this mysheet.css document
with a <link> tag coded in the <head> section of the page. With this, the page can have
all the styles defined in that linked file.
<head>
<link href="mysheet.css" type="text/css" rel="stylesheet">
</head>
<body>
<h1> Hello </h1>
<p> Welcome to Apoorva </p>
<h2 class="mystyle"> Thankyou </h2>
<body>
A style sheet may be imported with the @import statement. This statement may be
used in a CSS file or inside the STYLE element. This can be used to import .css files from
other directories or other servers. The following example shows importing .css files
from other server and other directory.
<style type="text/css">
tag {property:value; ...} /* Simple selector */
tag, tag,... {property:value; ...} /* Group selectors */
tag sub-tag ... {property:value; ...} /* Contextual selector */
#id {property:value; ...} /* Id selector */
.class {property:value; ...} /* Class selector */
tag.class {property:value; ...} /* sub-class Selector */
tag:pseudo-class {property:value; ...} /* pseudo-class Selector */
</style>
<style type="text/css">
p {font-family:arial; font-size:9pt}
</style>
<p> Welcome to Apoorva </p>
Group Selectors: In a similar manner, identical styles can be applied to multiple tags
by listing the tag names separated by commas. In the following example, all <h1>,
<h2>, and <h3> tags appearing on the page will have the same styling.
<style type="text/css">
h1, h2, h3 {font-family:arial; color:blue}
</style>
<h1> Welcome to Apoorva </h1>
<h2> Welcome to Apoorva </h2>
<h3> Welcome to Apoorva </h3>
Contextual Selectors: A contextual selector gives the combination of tags and sub-
tags (or nested tags) separated by spaces. For example, the contextual selector in the
example below is P EM. This rule says that emphasized text within a paragraph should
have a yellow background; <em> in other tags or <p> tag alone or <em> tag alone
would not affect the text in those tags.
<style type="text/css">
P EM { background: yellow }
</style>
<p> <em> Welcome </em> </p> <!-- displayed with yellow background -->
<p> Paragraph Text </p> <!-- displayed in its usual style -->
<em> Emphasized Text </em> <!-- displayed in its usual style -->
<style type="text/css">
#MyPar {font-family:arial; font-weight:bold}
</style>
<p id="MyPar"> Welcome to Apoorva </p>
<style type="text/css">
.mystyle{font-family:arial; font-size:10pt; color:blue}
</style>
<p class="mystyle"> Welcome to Apoorva </p>
<h1 class="mystyle"> Know More </h1>
Sub-Class Selectors: A simple selector can have different classes, thus allowing the
same element to have different styles. For example, we may wish to display <h1> in a
different color depending on the class value it uses in the corresponding tag.
<style type="text/css">
H1.style1 { color: red }
H1.style2 { color: blue }
</style>
<h1 class="style1"> Know More </h1>
<h1 class="style2"> Grow More </h1>
A general style that can be applied to any tag is known as a style class and is
defined by assigning a class name, preceded by a period (.), to its style properties.
Style classes are also known as class selectors.
One element (tag) can have only one class attribute, but the same class can be
used in many different tags.
Style classes can be defined in embedded styles and external styles.
B- Com III – Web Programming
106 Apoorva Publishers
In the following example, a class named “.mystyle” is created. This can be used in
any tag as the value of “class” attribute with in that.
<head>
<style type="text/css">
.mystyle{font-family:arial; font-size:10pt; color:blue}
</style>
</head>
<body>
<p class="mystyle"> Welcome to Apoorva </p>
<h1 class="mystyle"> Know More </h1>
</body>
float Declares whether a box should float left, right, none div { float:left; }
to the left or right of other content or div { float:right; }
not
visibility Declares the visibility of an element Visible, hidden, div { visibility:visible; }
collapse div { visibility:hidden; }
top Declares the distance between Lengths, div { top:15px; }
bottom content edge of the element and its percentages, and div { left:2%; }
right containing block accordingly the predefined
left (position should not be static) value auto.
Pixeltop Positioning values in pixels Only integer div { pixelleft:100; }
Pixelbottom values
Pixelleft
Pixelright
position Declares the type of positioning of an Static, relative, div { position:absolute; }
element absolute, fixed div { position:relative; }
z-index Declares the stack order of the Integer values or div { z-index:2; }
element. auto. div { z-index:auto; }
caption-side Declares where the table top, bottom, left, caption { caption-side:top; }
caption is displayed in right caption { caption-side:right; }
relation to the table.
empty-cells Declares the way empty show, hide table { empty-cells:show; }
cells are displayed (if table { empty-cells:hide; }
border-collapse is
separate).
table-layout Declares the type of table auto, fixed table { table-layout:auto; }
layout table { table-layout:fixed; }
To position the images as shown in the above program, we use the CSS style property
‘position’ with ‘absolute’ as its value. When we use this option, the exact positioning
can be set using the properties left and top. The following program positions the three
images as required.
<html>
<body>
<img src="face.gif" width=100 height=100
style="position:absolute; left=0; top:0">
<img src="face.gif" width=100 height=100
style="position:absolute; left=100; top:100">
<img src="face.gif" width=100 height=100
style="position:absolute; left=200; top:200">
</body>
</html>
21. What is an Event? Explain Event handling in DHTML. (Or) Discuss about Dynamic HTML
Event Model with the help of an example.
Event: Events are various actions that take place in a program. Script can be invoked
when an associated event triggers. DHTML combined with scripts (VBScript, JavaScript)
allow for event-driven programming.
Events can be triggered by performing specified action on different form elements
or HTML elements such as buttons, checkboxes, radio buttons, form, table and etc
Each element may support several different events. For example, the <body> tag
supports the events like onclick, onload, onunload, onmousedown an etc.
Events Meaning
onclick When a mouseclick happens on an element
ondblclick When a mouse-doubleclick happens on an element
onblur When an element loses focus
onfocus When an element gets focus
onkeydown When a keyboard key is pressed
onkeyup When a key is released
onkeypress When a keyboard key is pressed or held down
onmousedown When a mouse button is held down
onmouseup When mouse button is released
onmousemove When mouse moves
onmouseout When muse cursor is moved out of the control
onmouseover When mouse moves over the control
Example: The following program changes the color of the text to blue when the mouse
moves over the text “Welcome to Apoorva” and it turns “black” when the mouse
comes out of that. It uses two events: onMouseOver and onMouseOut.
OnClick: A click event occurs when a button, checkbox, radio button, reset button, or
submit button is clicked using left mouse button. This event is commonly used with a
button to start script execution.
Example (VBScript): In the example below, when we click on the button "Click Me" it
will execute the VBScript statement " VBScript:msgbox('U Clicked Me')" and gives the
message “U Clicked Me”.
<body>
<form>
<input type="Button" value="Click Me"
onClick="VBScript:msgbox('U Clicked Me')">
</form>
</body>
Example (DHTML with VBScript): The following program uses three button controls
with onclick event. When the buttons are clicked, the text will be aligned (left or right
B- Com III - Web Programming
Apoorva Publishers 113
or center) according to the button clicked. It uses the CSS property “textalign” to align
the text.
<script language="VBScript">
sub f1(obj)
hid.style.textalign = obj.value
end sub
</script>
<body>
<form name="frm">
<h1 id="hid"> welcome </h1>
<input type=button name="B1" value="Left"
onclick="f1(me)">
<input type=button name="B2" value="Center"
onclick="f1(me)">
<input type=button name="B3" value="Right"
onclick="f1(me)">
</form>
</body>
OnDblClick: A Double Click event occurs when a button, checkbox, radio button, reset
button, or submit button is double clicked.
<script language="VBScript">
sub B1_OnDblClick()
hid.style.visibility="hidden"
end sub
</script>
<body>
<form>
<h2 id="hid"> I will disappear </h2>
<input type=button value="Hide" name="B1">
</form>
</body>
Example 2: The following program changes the color of the text to blue when the
mouse moves over the text “Welcome to Apoorva” and it turns “black” when the
mouse comes out of that. It uses two events: onMouseOver and onMouseOut.
<script language="VBScript">
sub f1()
head1.style.color ="blue"
end sub
sub f2()
head1.style.color ="black"
end sub
</script>
<body>
<h1 id="head1" onmouseover="f1()" onmouseout="f2()">
Welcome to Apoorva
</h1>
</body>
OnMouseDown: When a mouse button is held down, this event fires and the
associated procedure will be executed.
OnMouseUp: When mouse button is released, this event fires and the associated
procedure will be executed.
OnMouseMove: When the mouse moves, this event fires and the associated
procedure will be executed.
Example: The following program uses the three events: onmousedown, onmouseup
and onmousemove. It - displays the message “mousedown” when the mouse button is
held down; displays “mouseup” when we release the mouse button; displays the
mouse cursor position (x, y values) within the browser.
<script language="VBScript">
sub f1()
head1.innerHTML ="mousedown"
end sub
sub f2()
head1.innerHTML ="mouseup"
end sub
sub f3()
head1.innerHTML=window.event.clientx & "," & _
window.event.clienty
end sub
</script>
27. Write short notes on ONKEYDOWN, ONKEYUP, ONKEYPRESS events with example. (Or)
Explain Keyboard related events.
Example: The following program demonstrates the use of the three keyboard events. It
displays the character pressed and its uni-code in two text boxes when the user presses
and releases a key. It also displays a message in the window status bar.
<script language="VBScript">
sub f1()
frm.t1.value=chr(window.event.keyCode)
end sub
sub f2()
frm.t2.value=window.event.keyCode
end sub
</script>
onFocus: This event occurs when a control gains its input focus. A control gains a focus
when a user tabs into or clicks on elements like password, text-field, textarea, button
and so on. This indicates that a control is ready to receive input or to be clicked.
Example: In the following example when the user clicks in the text box (onfocus), the
background of the text becomes light green; and when the user moves out of the text
box (onblur), the background of the text becomes white. Similarly, when the user
moves on to the button from the textbox using tab, the message ‘click me now’ will be
displayed in the status bar.
<body>
<form>
<input type=text id="t1"
onFocus="t1.style.background='lightgreen'"
onBlur="t1.style.background='white'" >
<input type=button value="OK"
onFocus="window.status='click me now'">
</form>
</body>
onChange: This event is triggered by a text box (text, file, text-area, select) being
changed, then the changes being registered by pressing ‘tab’. That is, the event fires
when the contents of the object or selection have changed.
Example: In the following example, the two text boxes display initial values ‘Ravi’ and
‘Karimnagar’; and when they are changed by the user, the program asks for
confirmation to save the new values or to revert back to default values. It uses the
event “OnChange()”.
<script language="VBScript">
sub f1()
B- Com III – Web Programming
118 Apoorva Publishers
k = msgbox ("Text Changed! Save it?", vbYesNo)
if k=vbNo then
frm.reset
end if
end sub
</script>
<body>
<form name="frm">
<h4> OnChange Event Demo </h4>
Name:<input type=text name="t1" value="Ravi"
onChange="f1()">
<br>City:<input type=text name="t2" value="Karimnagar"
onChange="f1()">
</form>
</body>
onLoad: The load event triggers when the browser finishes loading a document. This
may be used when we want to initialize values for variables or to understand the
version and type of the browser and controlling the formatting accordingly.
onUnload: This event occurs during the unloading of the page from the browser,
before any HTML elements have been destroyed. The unload event occurs when we
move to a new document by using hyperlinks or close the current document.
Example: In the following example, when the page is initially loaded, it displays a
message “welcome to my site”; and when we close the page, it displays “thanks for
visiting my site”.
<script language="VBScript">
sub f1()
msgbox "Welcome to My site"
end sub
sub f2()
msgbox "Thanks for Visiting My site"
end sub
</script>
<body onload="f1()" onunload="f2()">
<h1> This is My Site </h1>
</body>
onSelect: The onselect event occurs when a user selects some text in a text field. This
attribute may be used with TextArea and Text elements.
Example: In the following program, when the user selects either by dragging the mouse
or using shift and arrow buttons, the selected text will be displayed in the second text
box.
<script language="VBScript">
sub f1()
frm.t2.value=document.selection.createRange().text
end sub
</script>
<body>
<form name="frm">
<h4> oneselect event demo </h4>
Enter a string <input type=text name="t1"
onselect="f1()">
<br>Selected Text : <input type=text name="t2">
</form>
</body>
onSubmit: A submit event occurs when the user submits a form. This event is used
with a form and a submit button. This may initiate a data-validation script or directly
send data to server. When it initiates a script, to cancel the event i.e. to cancel
submission of data, we write “formname_onsubmit =false” in the event
function. If we want to submit the data we write “formname_onsubmit =true”
in the event function.
Example: In the following example when the user clicks on the submit button, it will
execute the function "frm_OnSubmit()". If the form the validation tests (here, name
should not be numeric), a true value is returned and the data will be passed to the
<script language="VBScript">
function frm_OnSubmit()
s = frm.t1.Value
If IsNumeric(s) or trim(s)="" Then
msgbox "Name is not vaild"
frm_OnSubmit=false
else
msgbox "Submitting your name now"
frm_OnSubmit=true
end if
end function
</script>
<body>
<form name="frm"
action="http://localhost/myasp/test.asp">
Enter name: <input type=text name="t1">
<input type=submit>
</form>
</body>
Onreset: The onreset event occurs when a form is reset. It only applies to the FORM
elements. It clears the values of all the form elements or sets their default values.
Example: In the following example, after entering values in the text boxes, if the user
presses “reset” button, the program puts a confirmation whether to reset the values or
retain the values (i.e. to cancel resetting). Depending upon the user’s response it
resets the values or cancels the resetting.
<script language="VBScript">
function frm_onReset()
k = msgbox ("Reset all values?", vbYesNo)
if k=vbNo then
frm_onReset=false
else
frm_onReset=true
B- Com III - Web Programming
Apoorva Publishers 121
end if
end function
</script>
<body>
<form name="frm" >
<h4> OnReset Event Demo </h4>
Name: <input type=text name="t1">
<br>City: <input type=text name="t2">
<br> <input type=reset >
</form>
</body>
OnError: The onerror event is triggered when an error occurs loading a document or an
image or because of script errors. Even the syntactical errors can be monitored using
this. We can take alternate measures in the case of errors.
Example: The following program uses OnError event to capture the VBScript errors
while loading the page. The program has two error causing statements and in the
ouput, it is shown what the errors, sources and the line numbers are.
<SCRIPT language=VBScript>
set window.onerror = GetRef("Handler")
function Handler ( msg, url, line )
document.write "<BR>Error : " & msg
document.write "<BR>File : " & url
document.write "<BR>Line No : " & line
Handler=true
End function
t1.value=30 'error causing statement
</SCRIPT>
<SCRIPT language=VBScript>
document.write "Hello 'error causing statement
</SCRIPT>
Output:
Error : Object required: 't1'
File : file:///C:/test.html
Line No : 9
Error : Unterminated string constant
File : file:///C:/test.html
Line No : 13
35. Explain about the "CreateElement" method in Dynamic content. (or) How to
create elements dynamically?
CreateElement: The createElement method creates a stand-alone element under the
document object dynamically i.e. after the page is loaded using event handling. We can
create any element except frame and iframe. The HTML tag is the only parameter we
need to specify when calling the createElement. To create a <FONT> tag element, we
would write:
fontobj.face ="arial"
fontobj.color ="red"
fontobj.innerHTML ="Welcome"
document.body.insertbefore(fontobj)
Example: The following program creates buttons dynamically after loading the page.
Each time we click the button labeled “create buttons”, it creates a new button.
<BODY>
<INPUT TYPE="BUTTON" ONCLICK="createButton()"
VALUE="Create Buttons">
</BODY>
<SCRIPT LANGUAGE="VBScript">
dim k,tab1
k=1
sub createTable()
set tab1= document.createElement("table")
tab1.border=1
tab1.width=300
document.body.insertbefore(tab1)
end sub
sub f1()
set r=tab1.insertRow()
for i=0 to 2
set c1 = r.insertCell()
c1.innerHTML = "data " & k
k=k+1
next
end Sub
B- Com III – Web Programming
124 Apoorva Publishers
Sub f2()
tab1.deleterow()
k=k-3
end sub
</SCRIPT>
<BODY onload="createTable()">
<form>
<INPUT TYPE="BUTTON" NAME="B1" VALUE="Add Row"
onclick="f1()">
<INPUT TYPE="BUTTON" NAME="B2" VALUE="Delete Row"
onclick="f2()">
</form>
</BODY>
37. With an example, explain how to change text, attributes, style, and graphics
dynamically.
Using DHTML (scripting, css, html) we can change the text, attributes, style and
graphics of HTML elements dynamically.
Element-id.innerHTML = “value”
Example: The following program changes the text of <h1> to “Hello World”, when we
click on the button.
<SCRIPT LANGUAGE="VBScript">
sub f1()
hid.innerHTML = "Hello World"
end sub
</SCRIPT>
<BODY>
<h1 id="hid"> Welcome </h1>
<INPUT type="button" NAME="B1" value="Change Text"
onclick="f1()">
</BODY>
Example: The following program changes the font size and color of <font> element
when we click on the button.
<SCRIPT LANGUAGE="VBScript">
sub f1()
fid.color = "blue"
fid.size = 6
end sub
</SCRIPT>
<BODY>
<font color=red size=3 id="fid"> Welcome </font> <br>
<INPUT type="button" NAME="B1" value="Change Font"
onclick="f1()">
</BODY>
Element-id.style.property = “value”
Example: The following program changes the color of the <h1> element and underlines
it when we click on the button.
<SCRIPT LANGUAGE="VBScript">
sub f1()
hid.style.color = "blue"
hid.style.textdecoration = "underline"
end sub
</SCRIPT>
<BODY>
<h1 id="hid"> Welcome </h1>
<INPUT type="button" NAME="B1" value="Change Style"
onclick="f1()">
</BODY>
<SCRIPT LANGUAGE="VBScript">
sub f1()
img1.src = "logo2.gif"
end sub
</SCRIPT>
<BODY>
<img id="img1" src="logo1.gif">
<INPUT type="button" NAME="B1" value="Change Image"
onclick="f1()">
</BODY>
Filters: Visual filters are prepackaged effects behavior that allow us to easily apply
visual effects to their content. Visual filters and transitions are currently supported
only in Microsoft Internet Explorer, but are proposed extensions to the Cascading Style
Sheet (CSS2) specification. Filters can be applied to HTML control elements through
the CSS filter property.
For inline styles, the syntax for a filter property is:
style="filter: filtername ( parameters )"
For embedded and linked style sheets, the syntax is:
selector { filter: filtername ( parameters ) }
Uses:
Filters can be applied both on text and images
They do not require much code, they can be written inline also.
Filters can be changed dynamically.
We can also combine filters i.e. we can apply more than one filter on one element.
Elements that can use filters: Visual filters can be applied to HTML elements that are
controls. A control element is one that defines a rectangular space within a browser
window. Valid HTML elements where filters can be applied are: BODY, BUTTON, DIV,
IMG, INPUT, MARQUEE, SPAN, TABLE, TR, TH, TD, TFOOT, THEAD, TEXTAREA.
The DIV and SPAN requires a defined height, width, or absolute position for a filter to
be applied. Filters are ignored for any positioned elements nested inside nonpositioned
elements, such as a positioned SPAN inside a nonpositioned DIV. Headings and
paragraphs, can be applied a filter if they are within a positioned DIV.
Filter Description
Alpha Sets the level of opacity for a visual object.
Blur Blurs an object in the specified direction and strength.
Chroma Renders a specified color in the object transparent.
Drop Shadow Creates a shadow of the object at the specified x-y offset and color.
Flip Horizontal Creates a mirror image of the visual object, horizontally.
Flip Vertical Creates a mirror image of the visual object, vertically.
Glow Gives the object the appearance of a glow.
Grayscale Renders the object in grayscale.
Invert Reverses the hue, saturation, and brightness values of the visual
object.
Light Simulates the projection of a light source onto the object.
Mask Makes a transparent mask of the visual object.
Shadow Creates a shadow around the object in the direction and color
specified.
Wave Creates a wave-like distortion of the object along its vertical axis.
XRay Transforms the visual display to monochromatic x-ray film.
Example 2: The following example demonstrates other filters such as: gray, invert, xray,
wave, mask, alpha, blur, and chroma.
<tr>
<td> Mask </td>
<td> Alpha </td>
<td> Blur </td>
<td> Chroma </td>
</tr>
<tr>
<td style="filter:mask(color=red)"> <img src="face.jpg"> </td>
<td style="filter:alpha(opacity=50)"> <img src="face.jpg"> </td>
<td style="filter:blur(strength=20)"> <img src="face.jpg"> </td>
<td style="filter:chroma(color=blue)"> <img src="face.jpg"> </td>
</tr>
</table>
Output:
Transitions: Transitions are time-varying visual filters. Their use is to visually transition
an object from one state to the next. Two transition filters exist with Internet Explorer:
Blend Transition and Reveal Transition.
1. Blend Transition: The blend transition filter allows a simple fade-in or fade-out of
an object with a specified duration. The following example shows how to apply
the blend transition to simulate an automatic slide show between images.
<script language="VBScript">
sub doTrans()
img1.filters.blendTrans.Apply()
img1.src = "face2.jpg"
img1.filters.blendTrans.Play()
end sub
</script>
in which the ‘Duration’ is Length of time the transition and the value is expressed
in seconds.milliseconds; and ‘Transitionshape’ is the type of the transition; i.e. a
value from 0 to 23. The transition types and the values are shown in the following
table.
<script language="VBScript">
sub doTrans ()
img1.filters.revealTrans.Apply()
img1.src="face2.jpg"
img1.filters.revealTrans.Play()
end sub
</script>
<img id="img1" src="face1.jpg" width=200 height=200
style="filter:revealTrans(transition=8,duration=5)">
<br><button onclick="doTrans()">Play Demo</button>
40. How Multimedia effects can be created using DHTML? (Or) Discuss about Filters and
Transitions existing in DHTML in detail.
Multimedia effects in DHTML can be created using Filters and transitions. These are
supported by Internet Explorer. Using this, one can easily develop more visually
appealing web pages with special effects without having to write much code.
4 ASP
1. What is ASP? What are its Features and Advantages? (Or) What is ASP?
What is the importance of ASP technology? Explain.
2. What is Server Side Programming?
3. What is ASP Script Engine? (Or) What is Server side Script Engine?
4. Explain about ASP Architecture. (Or) Explain how ASP pages really work.
5. Explain the process of serving ASP page? (Or) Write the procedure for an
Execution of ASP source code.
6. Using ASP how you will submit data to server. Give an example. Explain the
steps.
7. What are ASP Tags? How do you write ASP code? (or) What is the structure
of an ASP program?
8. Explain briefly about ASP Objects.
9. Explain “Application” object in ASP.
10. Explain “ASPError” object in ASP.
11. Explain “Request” object in ASP.
12. Explain “Response” object in ASP.
13. Explain “Server” object in ASP.
14. Explain “Session” object in ASP. (Or) What is the use of Session Object?
15. Explain the Events of Session - on Start and Session - on End.
16. Explain the object “FileSystemObject”.
17. Explain the object “TextStream” with an example.
18. Explain the object “File” with an example.
19. Explain the object “Folder” with an example.
20. Explain the object “Drive” with an example.
21. Explain the object “Dictionary” with an example.
Active Server Pages (ASP) is used to create dynamic and interactive Web pages. An ASP
page is a Hypertext Markup Language (HTML) page that contains script commands that
are processed by the Web server before sending it to the client's browser. An ASP file
can contain text, HTML tags and scripts. The scripting language can be VBScript,
JavaScript and so on.
Features of ASP:
ASP stands for Active Server Pages
ASP is a Microsoft Technology
ASP is a program that runs inside IIS (IIS stands for Internet Information Services)
ASP programs are meant for server side programming
It is purely meant for web applications
It supports DBMS and Active X controls
It has so many built in objects and components.
The asp files take the extension “.asp”.
The default scripting language is VBScript.
Advantages:
Server-side scripting does not have any browser limitations.
Disadvantages:
Server-side scripts require that their language's interpreter be installed on the
server.
They create burden on the server resulting more network traffic.
Program: The following program is simple example for server side programming that
uses ASP. The HTML file submits the name value to the server-file which in turn directs
the output to browser.
Test.asp
<%
response.write ("Hello " & _
request.querystring("t1"))
%>
Test.html
<form name="frm"
action="http://localhost/myasp/test.asp">
Name: <input type="text" name="t1" > <BR>
<input type="submit" name="submit">
</form>
3. What is ASP Script Engine? (Or) What is Server side Script Engine?
Script Engine: The script engine implements all the functions and procedures that can
be used in script programs. Without script engine, we cannot execute our script
programs.
ASP Script Engine: ASP Script engine is a server-side script engine. This is installed on
the web server and is responsible for processing ASP scripts. It is the responsibility of
ASP engine to process the ASP scripts and send the results back as HTML text to the
ASP File
Initiates
VBScript
ASP Script Engine Other Script Engines
JavaScript
Executes ASP file & Results
HTML content
4. Explain about ASP Architecture. (Or) Explain how ASP pages really work.
ASP files reside at web servers. As ASP files are meant for server side programming in
web applcations, one can access ASP files using web-clients and through web pages in a
browser.
ASP architecture constitutes the following: The running of ASP file requires the
following.
Web server: This is where an ASP file is deployed. All the requests sent by the
clients are submitted to a web-server.
Web Client: This is a user’s machine from which he wants to access the server to
fetch information required.
Browser: Web applications (pages) can be viewed only in browsers. Similarly,
requesting an asp page can also be done only through browsers like Internet
Explorer.
ASP Engine: ASP Script engine is a server-side script engine. This is installed on the
web server and is responsible for processing ASP scripts. The ASP engine also
invokes vbscript.dll to run VBScript scripts or JavaScript engine to run JavaScript
based scripts.
Request: This is the information sent from a client to web server.
Response: This is the information sent from a web server to a client.
Working of an ASP program: The process of the working of an ASP program is given
below.
The web client sends a request to an ASP file using browsers.
This request is sent to the server of the destiny
file.asp
<HTML>
<BODY>
Web Server <% Response.write “<h1>” & Date() & “</h1>” %>
</BODY>
</HTML>
Request
Response
file.asp
<HTML> Displayed in browser as
Web Client <BODY>
<h1> 10/10/2010 </h1> 10/10/2010
</BODY>
</HTML>
5. Explain the process of serving ASP page? (Or) Write the procedure for an Execution of
ASP source code.
1. We first create an asp file with some asp code in that. The extension of the file
should be “.asp”. Say “test.asp”.
2. The IIS(Internet Information Server) must be installed in the computer prior to
deploying asp file.
3. We then place the asp file in a sub directory (say ‘myasp’) of “inetpub/wwwroot”.
This process is called deploying asp file in a server.
4. Now, we open the browser and type in the path to access the asp file. In a Local
machine it could be “http://localhost/myasp/test.asp”.
6. Using ASP how you will submit data to server. Give an example. Explain the steps.
To submit data to a server, we usually require a HTML page with form elements or we
may also send the data in the form of manually written query strings. Sending the data
to a server and processing or manipulating the data there and have it displayed in the
client’s browser is nothing but server side programming.
When we send the data through a HTML file, it frames q query sting containing names
of the form elements and their values. A query string takes the following format.
t1=ravi&t2=33&t3=arun
Where, t1, t2 and t3 are form elements and ravi, 33 and arun are their values.
Program: Let us consider a simple HTML file with a text box. The program is an example
for server side programming which sends data to server. The HTML file submits the
name value to the server-file which in turn redirects the output to browser.
Test.asp
<%
response.write("Hello" & request.querystring("t1"))
%>
Test.html
<form name="frm" action="http://localhost/myasp/test.asp">
Name: <input type="text" name="t1" > <BR>
<input type="submit" name="submit">
</form>
The execution process when the data is submitted to a server is explained below.
Note: Refer to the “Working of an ASP program” in the question no.
7. What are ASP Tags? How do you write ASP code? (or) What is the structure of an ASP
program.
To write ASP code, we use the following tag i.e. the entire ASP code has to be put in
these tags.
Syntax:
<%
X=30
Y=40
Response.write ("Sum =" & (x+y))
%>
Active Server Pages consist of the following seven important built in objects. They are
readymade objects, which provide functionality to the web pages.
An application may consist of several ASP files that work together to perform some
purpose. The Application object is used to tie these files together. The Application
object holds information that will be used by many pages in the application. The
information can be accessed from any page. The information can also be changed in
one place, and the changes will automatically be reflected on all pages. The Application
object's collections, methods, and events are described below:
COLLECTIONS
Collection Description
Contents Contains all the items appended to the application through a script
command
StaticObjects Contains all the objects appended to the application with the HTML
<object> tag
METHODS
Method Description
Contents.Remove Deletes an item from the Contents collection
Contents.RemoveAll() Deletes all items from the Contents collection
Lock Prevents other users from modifying the variables
Unlock Enables other users to modify the variables
EVENTS
Example: The following program demonstrates the use of “Application” object. It sets
three application wide variables and uses “remove()” method.
<%
Application("Author")="Venu"
Application("Year")= "2010"
Application("Subject")="WebTech"
Application.Contents.Remove(2)
for each x in Application.Contents
Response.Write(x & "=" & Application.Contents(x)&"<br>")
next
%>
Output:
Author=Venu
Subject=WebTech
ASPError Object: ASPError Object describes the properties of the object that stores
information about an error condition. This object is used to display detailed
information of any error that occurs in scripts in an ASP page. The ASPError object's
properties are described below.
Property Description
ASPCode Returns an error code generated by IIS
ASPDescription Returns a detailed description of the error
Category Returns the source of the error
Column Returns the column position within the file that generated the error
Description Returns a short description of the error
File Returns the name of the ASP file that generated the error
Line Returns the line number where the error was detected
Number Returns the standard COM error code for the error
Source Returns the actual source code of the line where the error occurred
<%
dim objErr
set objErr=Server.GetLastError()
response.write("<BR>Number=" & objErr.Number)
response.write("<BR>Description=" & objErr.Description)
response.write("<BR>File=" & objErr.File)
response.write("<BR>Line=" & objErr.Line)
response.write("<BR>Source=" & objErr.Source)
%>
Request Object: Request Object describes the methods, properties, and collections of
the object that stores information related to the HTTP request. This includes forms,
cookies, server variables, and certificate data.
When a browser asks for a page from a server, it is called a request. The Request object
is used to get information from a visitor. Its collections, properties, and methods are
described below:
COLLECTIONS
Collection Description
ClientCertificate Contains all the field values stored in the client certificate
Cookies Contains all the cookie values sent in a HTTP request
Form Contains all the form (input) values from a form that uses the
post method
QueryString Contains all the variable values in a HTTP query string
ServerVariables Contains all the server variable values
PROPERTIES/METHODS:
Method Description
TotalBytes Returns the total number of bytes the client sent in the body of the
(property) request
BinaryRead Retrieves the data sent to the server from the client as part of a
post request and stores it in a safe array
Example: The following program demonstrates the use of “Request” object. The
program prints the values of “fruit” and “flower” obtained through a query string. Here
B- Com III – Web Programming
142 Apoorva Publishers
we can pass the query string manually when executing the asp file as shown below.
http://localhost/myasp/test.asp?fruit=Apple&flower=Rose
Test.asp
<%
Response.Write "Fruit =" & Request.QueryString("fruit")
Response.Write "<br>Flower =" &
Request.QueryString("flower")
%>
Output:
Fruit=Apple
Flower=Rose
Response Object: Response Object describes the methods, properties, and collections
of the object that stores information related to the server's response. This includes
printing content, manipulating headers, setting locales, and redirecting requests. It is
used to send output to the user from the server. Its collections, properties, and
methods are described below:
COLLECTIONS
Collection Description
Cookies Sets a cookie value. If the cookie does not exist, it will be created.
PROPERTIES
Property Description
Buffer Specifies whether to buffer the page output or not
CacheControl Sets whether a proxy server can cache the output or not
Charset Appends the name of a character-set to the content-type
header in the Response object
ContentType Sets the HTTP content type for the Response object
Expires Sets how long (in minutes) a page will be cached on a browser
before it expires
ExpiresAbsolute Sets a date and time when a page cached on a browser will
expire
IsClientConnected Indicates if the client has disconnected from the server
Pics Appends a value to the PICS label response header
Status Specifies the value of the status line returned by the server
Example: The following program demonstrates the use of “Response” object. The
program sets a cookie value in a program, and accesses it another program.
Test1.asp
<%
Response.Cookies("firstname")="Kiran"
Response.write("Cookie has been created")
%>
Test2.asp
<%
fname=Request.Cookies("firstname")
Response.write("Firstname=" & fname)
%>
Output:
Firstname=Kiran
Server Object: Server Object describes the methods and properties of the object that
provides methods for various server tasks. With these methods we can execute code,
get error conditions, encode text strings, create objects for use by the Web page, and
map physical paths. Its properties and methods are described below:
PROPERTIES
Property Description
ScriptTimeout Sets or returns the maximum number of seconds a script can run
before it is terminated
METHODS
B- Com III – Web Programming
144 Apoorva Publishers
Method Description
CreateObject Creates an instance of an object
Execute Executes an ASP file from inside another ASP file
GetLastError() Returns an ASPError object that describes the error condition
HTMLEncode Applies HTML encoding to a specified string
MapPath Maps a specified path to a physical path
Transfer Transfers all the information created in one ASP file to another
URLEncode Applies URL encoding rules to a specified string
Example: The following program demonstrates the use of “Server” object. The program
executes a second asp file (“file2.asp”) using “execute” method from “file1.asp”.
File1.asp:
<%
response.write("I am in File 1<br >")
Server.Execute("file2.asp")
response.write("I am back in File 1")
%>
File2.asp:
<%
response.write("I am in File 2<br>")
%>
Output:
I am in File 1
I am in File 2
I am back in File 1
14. Explain “Session” object in ASP. (Or) What is the use of Session Object?
Session Object: Session Object describes the methods, properties, and collections of
the object that stores information related to the user's session, including variables and
objects that exist for the lifetime of the session.
A session is the time elapsed between opening and closing of a web application by a
user. Sessions are unique to users. ASP creates a unique cookie for each user. The
cookie is sent to the user's computer and it contains information that identifies the
user. This interface is called the Session object.
Variables stored in a Session object hold information about one single user, and are
available to all pages in one application. Common information stored in session
variables are name, id, and preferences. The server creates a new Session object for
B- Com III - Web Programming
Apoorva Publishers 145
each new user, and destroys the Session object when the session expires. The Session
object's collections, properties, methods, and events are described below:
COLLECTIONS
Collection Description
Contents Contains all the items appended to the session through a
script command
StaticObjects Contains all the objects appended to the session with the
HTML <object> tag
PROPERTIES
Property Description
CodePage Specifies the character set that will be used when displaying
dynamic content
LCID Sets or returns an integer that specifies a location or region.
SessionID Returns a unique id for each user. The unique id is generated
by the server
Timeout Sets or returns the timeout period (in minutes) for the
Session object in that application
METHODS
Method Description
Abandon Destroys a user session
Contents.Remove Deletes an item from the Contents collection
Contents.RemoveAll() Deletes all items from the Contents collection
EVENTS
Event Description
Session_OnEnd Occurs when a session ends
Session_OnStart Occurs when a session starts
Example: The following program demonstrates the use of “Session” object. The
program sets two session variables and prints all the contents of the session.
<%
Session("name")="Ramu"
Session("date")="10/10/2010"
A session is the time elapsed between opening and closing of a web application by a
user. Sessions are unique to users. ASP creates a unique cookie for each user which
contains information that identifies the user. This interface is called the Session object.
Session object in asp provides two events: Session_OnStart and Session_OnEnd. They
define the task to be done when a session starts and ends respectively. These events
are placed in the “Global.asa” file.
Session_OnStart Event: The Session_OnStart event occurs when the server creates
a session.
Session_OnEnd Event: The Session_OnEnd event occurs when the session ends
(abandoned or times out).
Syntax: Following is the general syntax used to write the above events in “global.asa”
file.
<script language="vbscript" runat="server">
Sub Session_OnStart
. . .
End Sub
Sub Session_OnEnd
. . .
End Sub
</script>
Example: The following program uses the two session events: Session_OnStart and
Session_OnEnd. This code should be written in the file “global.asa”. The second
program is used to print the number of visitors online.
Sub Session_OnStart
Application.Lock
Application("visitors")=Application("visitors")+1
Application.UnLock
End Sub
<%
response.write("No. of Online Visitors: " & _
Application("visitors"))
%>
Example: The following code uses FileSystemObject and creates a text file (c:\test.txt)
and then writes some text to the file.
<%
dim fs,fname
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fname=fs.CreateTextFile("d:\test.txt",true)
fname.WriteLine("Hello World!")
fname.Close
set fname=nothing
set fs=nothing
%>
The TextStream Object: The TextStream object is used to access the contents of text
files. To create an instance of the TextStream object we can use the CreateTextFile or
OpenTextFile methods of the FileSystemObject object, or we can use the
OpenAsTextStream method of the File object. The TextStream object's properties and
methods are described below:
PROPERTIES
Property Description
AtEndOfLine Returns true if the file pointer is positioned at the end-of-line
marker in a TextStream file, and false if not
AtEndOfStream Returns true if the file pointer is at the end of a TextStream file,
and false if not
Column Returns the column number of the current character position in
an input stream
Line Returns the current line number in a TextStream file
METHODS
Method Description
Close Closes an open TextStream file
B- Com III - Web Programming
Apoorva Publishers 149
Read Reads a specified number of characters from a TextStream file
ReadAll Reads an entire TextStream file and returns the result
ReadLine Reads one line from a TextStream file and returns the result
Skip Skips a specified number of characters when reading
SkipLine Skips the next line when reading a TextStream file
Write Writes a specified text to a TextStream file
WriteLine Writes a specified text and a new-line character into a file
WriteBlankLines Writes a specified number of new-line character into a file
Example: The following code creates a text file (c:\test.txt) and then writes some text
to the file and also reads the first line and prints it.
<%
dim fs,f,t,x
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.CreateTextFile("d:\test.txt")
f.writeline("Hello")
f.writeline("Welcome")
f.writeline("Bye")
f.close
set t=fs.OpenTextFile("d:\test.txt",1,false)
x=t.ReadLine
t.close
Response.Write("The first line in the file is:" & x)
%>
Output:
The first line in the file is: Welcome
The File Object: The File object is used to return information about a specified file. To
work with the properties and methods of the File object, we will have to create an
instance of the File object through the FileSystemObject object. First; create a
FileSystemObject object and then instantiate the File object through the GetFile
method of the FileSystemObject object or through the Files property of the Folder
object. The File object's properties and methods are described below:
PROPERTIES
Property Description
Attributes Sets or returns the attributes of a specified file
DateCreated Returns the date and time when a specified file was created
DateLastAccessed Returns the date and time when a specified file was last accessed
METHODS
Method Description
Copy Copies a specified file from one location to another
Delete Deletes a specified file
Move Moves a specified file from one location to another
OpenAsTextStream Opens a specified file and returns a TextStream object
Example: The following code uses the GetFile method of the FileSystemObject object
to instantiate the File object and prints the size, datecreated, path, name, and drive of
the file.
<%
Dim fs,f
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.GetFile("d:\test.txt")
Response.Write("<br>File created: " & f.DateCreated)
Response.Write("<br>File size: " & f.size)
Response.Write("<br>File path: " & f.path)
Response.Write("<br>File name: " & f.name)
Response.Write("<br>File drive: " & f.drive)
set f=nothing
set fs=nothing
%>
Output(sample):
File created: 12/4/2010 5:08:59 PM
File size: 1022
File path: C:\test.txt
File name: test.txt
File drive: c:
The Folder object's collections, properties, and methods are described below:
COLLECTIONS
Collection Description
Files Returns a collection of all the files in a specified folder
SubFolders Returns a collection of all subfolders in a specified folder
PROPERTIES
Property Description
Attributes Sets or returns the attributes of a specified folder
DateCreated Returns the date and time when a specified folder was created
DateLastAccessed Returns the date and time when a specified folder was last
accessed
DateLastModified Returns the date and time when a specified folder was last
modified
Drive Returns the drive letter of the drive where the specified folder
resides
IsRootFolder Returns true if a folder is the root folder and false if not
Name Sets or returns the name of a specified folder
ParentFolder Returns the parent folder of a specified folder
Path Returns the path for a specified folder
ShortName Returns the short name of a specified folder
ShortPath Returns the short path of a specified folder
Size Returns the size of a specified folder
Type Returns the type of a specified folder
METHODS
Method Description
Copy Copies a specified folder from one location to another
Delete Deletes a specified folder
Move Moves a specified folder from one location to another
CreateTextFile Creates a new text file in the specified folder and returns a
TextStream object to access the file
Output (sample):
Folder created: 10/10/2010 10:05:20 AM
The Drive Object: The Drive object is used to return information about a local disk drive
or a network share. The Drive object can return information about a drive's type of file
system, free space, serial number, volume name, and more.
To work with the properties of the Drive object, we will have to create an instance
of the Drive object through the FileSystemObject object. First, create a
FileSystemObject object and then instantiate the Drive object through the GetDrive
method or the Drives property of the FileSystemObject object. The Drive object's
properties are described below:
PROPERTIES
Property Description
AvailableSpace Returns the amount of available space on a given drive
DriveLetter Returns one uppercase letter that identifies the local drive
DriveType Returns the type of a specified drive
FileSystem Returns the file system in use for a specified drive
FreeSpace Returns the amount of free space to a user on a specified drive
IsReady Returns true if the specified drive is ready and false if not
Path Returns an uppercase letter followed by a colon that indicates the
path name for a specified drive
RootFolder Returns a Folder object that represents the root folder of a
specified drive
SerialNumber Returns the serial number of a specified drive
ShareName Returns the network share name for a specified drive
TotalSize Returns the total size of a specified drive or network share
VolumeName Sets or returns the volume name of a specified drive
B- Com III - Web Programming
Apoorva Publishers 153
Example: The following code uses the GetDrive method of the FileSystemObject object
to instantiate the Drive object and the TotalSize property to return the total size in
bytes.
<%
dim fs,d
set fs=Server.CreateObject("Scripting.FileSystemObject")
set d=fs.GetDrive("c:")
Response.Write("The total size in bytes is: " & _
d.TotalSize)
set d=nothing
set fs=nothing
%>
Output (sample):
The total size in bytes is: 4293563392
21. Explain the object “Dictionary” with an example.
PROPERTIES
Property Description
CompareMode Sets or returns the comparison mode for comparing keys in a
Dictionary object
Count Returns the number of key/item pairs in a Dictionary object
Item Sets or returns the value of an item in a Dictionary object
Key Sets a new key value for an existing key value in a Dictionary object
METHODS
Method Description
Add Adds a new key/item pair to a Dictionary object
Exists Returns a Boolean value that indicates whether a specified key exists in
the Dictionary object
Items Returns an array of all the items in a Dictionary object
Keys Returns an array of all the keys in a Dictionary object
Remove Removes one specified key/item pair from the Dictionary object
RemoveAll Removes all the key/item pairs in the Dictionary object
Example: The following example creates a Dictionary object, adds some key/item pairs
to it, and retrieves the item value for the key ‘gr’:
B- Com III – Web Programming
154 Apoorva Publishers
<%
Dim d
Set d=Server.CreateObject("Scripting.Dictionary")
d.Add "INR","Indian Rupee"
d.Add "USD","United Sates Dollar"
d.Add "GBP","Great British Pound"
d.Add "BDT","Bangladesh Taka"
Response.Write("The Full Currency Name for INR is:" & _
d.Item("INR"))
%>
Output:
The Full Currency Name for INR is: Indian Rupee
22. Write short notes on Data Access Technology? (Or) Write short notes on ADO (Active X
Data Object).
Data Access Technology: Data Access Technology in ASP pages facilitates working with
databases (creating, manipulating, and retrieving). To achieve this, we use ADO i.e.
ADO can be used to access databases from the web pages. The features of ADO are
listed below.
ADO stands for ActiveX Data Objects
ADO is a Microsoft Active-X component
ADO is automatically installed with Microsoft IIS
ADO is a programming interface to access data in a database
Accessing a Database from an ASP Page: The common way to access a database from
inside an ASP page is to:
1. Create an ADO connection to a database
2. Open the database connection
3. Create an ADO recordset
4. Open the recordset
5. Extract the data needed from the recordset
6. Close the recordset
7. Close the connection
Example: The following example uses “ADODB.connection” object and creates a table
named “student” in oracle. To connect to oracle we have used oracle DSN.
<%
set con=server.createObject(“ADODB.Connection”)
con.open “dsn=oradsn;uid=scott;pwd=tiger”
s=”create table student(rno number, sname varchar2(20))”
23. Write a short notes “Recordset” Object. (Or) Explain with an example the importance
and working with Recordset object.
Recordset Object: The ADO Recordset object is used to hold a set of records from a
database table. A Recordset object consist of records and fields. In ADO, this object is
the one used most often to manipulate data from a database. ADO Recordset object
can be created using “CreateObject()” method of Server object or the object can be
returned by “execute” method of Connection object.
Some of the commonly used properties and methods of Recordset object are listed
below.
PROPERTIES
Property Description
AbsolutePosition Sets or returns a value that specifies the ordinal position of the
current record
BOF Returns true if the current record position is before the first
record, otherwise false
Bookmark Sets or returns a bookmark. The bookmark saves the position of
the current record
DataSource Specifies an object containing data to be represented as a
Recordset object
EOF Returns true if the current record position is after the last
record, otherwise false
RecordCount Returns the number of records in a Recordset object
Sort Sets or returns the field names in the Recordset to sort on
METHODS
Method Description
AddNew Creates a new record
Close Closes a Recordset
Delete Deletes a record or a group of records
GetRows Copies multiple records from a Recordset object into a two-
dimensional array
B- Com III – Web Programming
156 Apoorva Publishers
Move Moves the record pointer in a Recordset object
MoveFirst Moves the record pointer to the first record
MoveLast Moves the record pointer to the last record
MoveNext Moves the record pointer to the next record
MovePrevious Moves the record pointer to the previous record
Open Opens a database element ( a table or the results of a query)
Save Saves a Recordset object to a file or a Stream object
Update Saves all changes made to a single record
<%
set con=server.createObject("ADODB.Connection")
set rs = Server.CreateObject("ADODB.recordset")
con.open "dsn=oradsn;uid=scott;pwd=tiger"
rs.open "select empno, ename, job from emp where
job='MANAGER'",con
while not rs.eof
response.write "<br>" & rs("empno") & " " & rs("ename")_
& " " & rs("job")
rs.movenext
wend
rs.close
con.close
%>
Output:
7566 JONES MANAGER
7698 BLAKE MANAGER
7782 CLARK MANAGER
ASP Components are the built-in components that enhance the functionality of the
web pages. The different components are explained below.
Property/Method Description
GetAdvertisement Returns HTML that displays the advertisement in the page
(method)
Border Specifies the border for the advertisement
B- Com III – Web Programming
158 Apoorva Publishers
Clickable Specifies whether the advertisement is a hyperlink
TargetFrame Name of the frame to display the advertisement
Example: Following are the two files: 1. “advt.txt” A text file containing banner
information and 2. “banners.asp” used to display banners and also for redirecting
when banners are clicked.
Advt.txt
REDIRECT banners.asp
*
apoorva.jpg
http://www.apoorvacollege.com
College with a difference
50
brain.jpg
http://www.winningbrains.com
Soft Skills made easy
50
Banners.asp
<%
url=Request.QueryString("url")
If url<>"" then Response.Redirect(url)
set adrotator=Server.CreateObject("MSWC.AdRotator")
response.write(adrotator.GetAdvertisement("advt.txt"))
%>
<%
Set MyBrow=Server.CreateObject("MSWC.BrowserType")
%>
Example: The example below creates a BrowserType object in an ASP file, and displays
some of the capabilities of the browser in use:
<html>
<body>
<%
Set MyBrow=Server.CreateObject("MSWC.BrowserType")
%>
B- Com III - Web Programming
Apoorva Publishers 159
<br>Client OS : <%=MyBrow.platform%>
<br>Web Browser : <%=MyBrow.browser%>
<br>Browser version : <%=MyBrow.version%>
<br>Frame support? : <%=MyBrow.frames%>
<br>Table support? : <%=MyBrow.tables%>
<br>Sound support? : <%=MyBrow.backgroundsounds%>
<br>Cookies support? : <%=MyBrow.cookies%>
<br>VBScript support? : <%=MyBrow.vbscript%>
<br>JavaScript support? : <%=MyBrow.javascript%>
</body>
</html>
Example:
Client OS : WinNT
Web Browser : IE
Browser version : 5.0
Frame support? : True
Table support? : True
Sound support? : True
Cookies support? : True
VBScript support? : True
JavaScript support? : True
Content Linking Component: The ASP Content Linking component is used to create a
quick and easy navigation system. The Content Linking component returns a Nextlink
object that is used to hold a list of Web pages to be navigated. The following syntax is
used to create Content Linking component.
<%
Set nl=Server.CreateObject("MSWC.NextLink")
%>
if (nl.GetListIndex("links.txt")>1) then
Response.Write("<br><a href='" & prv)
Response.Write("'>Previous Page</a><br>")
end if
Response.Write("<br><a href='" & nxt)
Response.Write("'>Next Page</a><br>")
%>
Then we create the files: File1.asp, File2.asp, and File3.asp and so on i.e. the files
listed in “links.txt”. In each of the .asp pages listed in the text file "links.txt", we
need to put the one line of code: <!-- #include file="nlcode.inc"--> and the
navigation will automatically work. For example the file “File1.asp” might have the
following code. Similarly all the other files.
File1.asp:
<!-- #include file="nlcode.inc"-->
<% response.write("First File Contents") %>
Method Description
GetListCount Returns the number of items listed in the List file
GetListIndex Returns the index number of the current item in the List file.
GetNextDescription Returns the text description of the next item listed in the List file.
GetNextURL Returns the URL of the next item listed in the List file.
GetNthDescription Returns the description of the Nth page listed in the List file
GetNthURL Returns the URL of the Nth page listed in the List file
GetPreviousDescription Returns the text description of the previous item listed in the List file
GetPreviousURL Returns the URL of the previous item listed in the List file.
%% #3
<img src="apoorva.gif">
%% #4
<a href="http://www.apoorvacollege.com">Visit Apoorva</a>
An ASP file that creates Content Rotator component and makes use of it. The
following is an example for that.
<%
set cr=server.createobject("MSWC.ContentRotator")
response.write(cr.ChooseContent("ads.txt"))
%>
<%
Set pc = Server.CreateObject("MSWC.PageCounter")
%>
Method Description
Hits(url) Returns the number of hits for a specified URL
Resest(url) Resets the page counter
Pagehit() Returns number of hits as a long integer
Example: The example below creates a PageCounter component in an ASP file, and
displays the number of hits to that page.
<%
Set pc = Server.CreateObject("MSWC.PageCounter")
response.write ("No of Hits = " & pc.PageHit())
%>
31. Write detailed notes on "Information Search Tools"/Index Services with examples.
Information Search tool: An information Search Tool gives the visitors a chance to find
something on a website by searching, much like the search engines such as Google. A
search tool will allow visitors to find the information quickly and without navigating
through hundreds of irrelevant results.
Generally, a web page contains many pages and lot of information. Though it has
better navigation options, many users want to locate a specific topic right away and
don’t want to follow links. Therefore, it is always a good idea to have a search facility in
every web site.
1) Search Engine: It is a program that accepts the request from the form or URL,
searches the index, and returns the results page to the server. Search engine
To display Date and time in an ASP page, we use two VBScript functions date and time.
As the default language in ASP is VBScript, they will work without any other inclusions.
The program is shown below. It displays the current date and time.
<%
response.write ("Date = " & Date)
response.write ("<br>Time = " & Time)
%>
Output (Sample):
Date = 11/5/2010
Time = 5:58:46 PM
5 XML
1. What is XML? What are the features of XML?
2. What is XML? What are the Uses/Advantages/Benefits of XML?
3. What are the Origin and Goals of XML?
4. What is XML? Write the structure of XML with an example.
5. What are Elements and Attributes in XML?
6. What are the main Components (building blocks) of XML document?
7. Explain the Rules of XML Syntax. (Or) What are the rules for Elements and
Attributes in XML.
8. What is XML and How to Customize XML documents?
9. Write short notes on XSL (Extensible Style Language).
10. Explain in detail about XML Style sheets.
11. What is DTD? Explain with an example.
12. What are the Rules (Syntax) for Declaring Elements and Attributes in a
DTD? (Or) Explain Declaring Elements and Attributes in a DTD.
13. What is DTD? Explain with an example i) Internal DTD ii) External DTD
14. What is Hyperlink? How we can accomplish this using XML? Explain with
the help of an example. (Or) Discuss about the use of Hyperlinks in XML
with example.
15. Explain XLink and XPoiner with Examples.
16. Explain Types of Links in XML. (Or) Explain Simple, Extended Links.
17. Explain Link (Linking) Elements.
18. Explain Link Behavior in XML Links.
19. Explain Link Timing in XML Links.
20. Discuss about Attribute Remapping with an example.
21. Define XML Parser and explain how to use XML with HTML.
22. Write a brief note on XML Document Object Model with an example.
23. Explain about XML Query language.
24. What are the differences between XML and HTML?
25. What are the differences between CSS and XSL?
26. What are the differences between XML and XSL?
27. What is Namespace?
XML: XML stands for Extensible Markup Language. XML is a general-purpose markup
language. It is classified as an extensible language because it allows its users to define
their own elements. Its primary purpose is to facilitate the sharing of structured data
across different information systems, particularly via the Internet.
XML Features:
XML is a subset of SGML
XML is a set of rules for encoding documents in machine-readable form.
XML is case sensitive
XML supports DOM (Document Object Model)
XML is designed to carry data, not to display data
XML tags are not predefined. We must define our own tags
XML is designed to be self-descriptive
XML is a W3C Recommendation
XML is the most common tool for data transmissions between all sorts of
applications.
XML data is stored in plain text format
XML is software and hardware independent.
XML: XML stands for Extensible Markup Language. XML is a general-purpose markup
language. It is classified as an extensible language because it allows its users to define
their own elements. Its primary purpose is to facilitate the sharing of structured data
across different information systems, particularly via the Internet.
XML Goals: The Goals of XML are defined by the XML W3C Working Group in the XML
Specifications as:
1. XML shall be straightforwardly usable over the Internet.
2. XML shall support a wide variety of applications.
3. XML shall be compatible with SGML.
4. It shall be easy to write programs which process XML documents.
5. The number of optional features in XML is to be kept to the absolute minimum,
ideally zero.
6. XML documents should be human-legible and reasonably clear.
7. The XML design should be prepared quickly.
8. The design of XML shall be formal and concise.
9. XML documents shall be easy to create.
10. Terseness in XML markup is of minimal importance.
Structure of XML: XML follows hierarchical tree like structure. This kind of
representation suits majority of data requirements. The structure of XML document is
shown below. XML documents may begin by declaring some information about
themselves, as in the following example (the first line).
Example: The following is a simple XML program. The root element in this program is
“address”.
Output: The output of the above program is shown below. When we click on “-“, the
elements collapse and the icon changes to “+”. Clicking this expands the child elements.
<?xml version="1.0" ?>
- <address>
- <name>
<first>Ravi</first>
<last>Kumar</last>
The Main Components (Building Blocks) of XML Documents: All XML documents are
made up by the following components. These are like different tokens in an XML
document.
Entities: Some characters have a special meaning in XML, like the less than sign (<)
that defines the start of an XML tag. To display such characters as they are, we use
entities. Entities are expanded when a document is parsed by an XML parser. The
following entities are predefined in XML:
PCDATA: PCDATA means parsed character data. PCDATA is text that will be parsed
by a parser. The text will be examined by the parser for entities and markup. Tags
inside the text will be treated as markup and entities will be expanded.
CDATA: CDATA means character data. CDATA is text that will NOT be parsed by a
parser. Inside the CDATA tags, the text will NOT be treated as markup and entities
will not be expanded.
Example: <statement> <![CDATA[x>y?x:y]]> </statement>
7. Explain the Rules of XML Syntax. (Or) What are the rules for Elements and Attributes in
XML.
All XML Elements Must Have a Closing Tag: In HTML, some of the elements do not
require closing tag like the tag <p>, though it is not an empty tag like <hr>. But in
XML all non-empty tags must have a beginning and a closing tag.
Incorrect : <p> This is a paragraph
Correct : <p> This is a paragraph </p>
XML Tags are Case Sensitive: XML tags are case sensitive. The tag <Letter> is
different from the tag <letter>. Opening and closing tags must be written with the
same case. Lower case element names are preferred in XML.
Incorrect : <address> This is a paragraph </Address>
Correct : <address> This is a paragraph </address>
XML Documents Must Have a Root Element: XML documents must contain one
element that is the parent of all other elements. This element is called the root
element.
Incorrect : <name> Raj </name> <rno> 33 </rno>
Correct : <student> <name> Raj </name> <rno> 33 </rno> </student>
XML Attribute Values Must be Quoted: XML elements can have attributes in
name/value pairs just like in HTML. In XML, the attribute values must always be
quoted; they may be omitted in HTML.
Incorrect : <font color=red> Apoorva </font>
Correct : <font color="red"> Apoorva </font>
Empty tags must have strat and end tags or end with ‘/>’: All empty XML
elements must have strat and end tags or end with ‘/>’
Incorrect : <hr>
Correct : <hr/> or <hr></hr>
Attribute minimization not allowed: XML does not support attribute minimization
as in the case of HTML (like checked). The attribute-value pairs must be written in
full.
Incorrect : <input type="radio" checked> Hi </input>
Correct : <input type="radio" checked="true"> Hi </input>
B- Com III - Web Programming
Apoorva Publishers 171
8. What is XML and How to Customize XML documents?
To customize XML documents, we use CSS (Cascade Style Sheet) formatting properties.
Using this, we can define how the user-defined tags should be displayed in the
browser. Here, we use external style sheets. The external style-sheet has to be
specified in the xml document using the following syntax.
Example: The following xml program when executed without “css”, only displays the
tree structure of elements. To format the elements, we have created “address.css” in
which the styles for the elements address, name, first, street, city, and pin are defined.
When we link the css file the output of the xml program will be different i.e. we will
have the formatted content displayed on the browser. The xml file (test.xml), css file
(address.css) and the output with and without style-sheets are shown below.
test.xml
<?xml version="1.0" ?>
<?xml-stylesheet type="text/css" href="address.css" ?>
<address>
<name>
<first> Ravi </first>
<last> Kumar </last>
</name>
<hno> 7/G </hno>
<street> Brindavan Colony </street>
<city> Karimanagr </city>
<pin> 505001 </pin>
</address>
address.css
address {display: block; border:"thin solid blue";
width:200; margin-bottom:20px}
name {color: blue; text-transform:uppercase;}
hno {display: block; font-style: italic;}
city, street {display: block; color: green;}
first {font-weight:bold;}
pin {color: red; font-size: 15pt; margin-left: 20pt;}
Output: Without CSS style sheet Output: With CSS style sheet
XSL: XSL stands for EXtensible Stylesheet Language. The World Wide Web Consortium
(W3C) started to develop XSL because there was a need for an XML-based Stylesheet
Language. Though CSS can be used to format XML documents, W3C recommends XSL
to style XML documents. Therefore, XSL is the preferred Style Sheets for XML.
As the browser does not know how to display XML tags, XSL describes how the XML
document should be displayed. XSL is more than a Style Sheet Language and it consists
of three parts:
XSLT: It is a language for transforming XML documents (Transformation)
XPath: It is a language for navigating in XML documents
XSL-FO: It is a language for formatting XML documents (Format Objects)
In simple terms, we can say that Extensible Stylesheet Language (XSL) is used to refer to
a family of languages used to transform and render XML documents.
Example: The following xml program uses xsl file (address.xsl) to style the xml
document (test.xml). Here, we are using the recommended stylesheet i.e. XSL
stylesheets to format our document. The output is also shown below.
test.xml
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="address.xsl"?>
<person>
<address>
<name> Srinivas </name> <city> Karimanagr </city>
</address>
<address>
<name> Ramu </name> <city> Hyderabad </city>
</address>
<address>
<name> Kiran </name> <city> Warangal </city>
address.xls
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Persons Database</h2>
<table border="1">
<tr bgcolor="cyan">
<th>Name</th>
<th>City</th>
</tr>
<xsl:for-each select="person/address">
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="city"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Output:
Persons Database
Name City
Srinivas Karimanagr
Ramu Hyderabad
Kiran Warangal
Stylesheets: Styles sheets are used to format HTML and XML documents. HTML can use
only CSS styles sheets, whereas XML documents can use both CSS style sheets and XSL
style sheets.
Valid XML document: An XML document is valid if it has an associated document type
definition and if the document complies with the constraints expressed in it.
12. What are the Rules (Syntax) for Declaring Elements and Attributes in a DTD? (Or)
Explain Declaring Elements and Attributes in a DTD.
DTD requires Declaring Elements and Declaring Attributes. The rules for declaring
elements and attributes are explained below.
Declaring Elements: In a DTD, XML elements are declared with an element
declaration with the following syntax:
Empty Elements: Empty elements are declared with the category keyword EMPTY:
<!ELEMENT element-name EMPTY>
Example: <!ELEMENT br EMPTY>
PCDATA Elements: Elements with only parsed character data are declared with
#PCDATA inside parentheses:
<!ELEMENT element-name (#PCDATA)>
Example: <!ELEMENT city (#PCDATA)>
Elements with any Contents: Elements declared with the category keyword ANY,
can contain any combination of parsable data:
<!ELEMENT element-name ANY>
Example: <!ELEMENT street ANY>
Elements with Children (sequences): Elements with one or more children are
declared with the name of the children elements inside parentheses:
<!ELEMENT element-name (child1,child2,...)>
13. What is DTD? Explain with an example i) Internal DTD ii) External DTD
DTD: Document Type Definition (DTD) is a set of markup declarations that define a
document type for markup languages like SGML, XML and HTML. DTD defines the legal
building blocks of an XML document. It defines the document structure with a list of
legal elements and attributes. A DTD can be declared inline within the XML document,
or as an external reference.
Internal DTD Declaration: If the DTD is declared inside the XML file, it should be
wrapped in a DOCTYPE definition with the following rules and syntax.
The document type definition must appear before the first element in the
document.
The name following the word DOCTYPE in the DTD must match the name of root
element.
Syntax: <!DOCTYPE root-element [element-declarations]>
<address>
<name> Ravi Kumar </name>
<hno> 7/G, Brindavan Colony </hno>
<city> Karimanagr </city>
<pin> 505001 </pin>
</address>
address.dtd:
<!ELEMENT address (name,hno,city,pin)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT hno (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT pin (#PCDATA)>
test.xml:
<?xml version="1.0"?>
<!DOCTYPE address SYSTEM "address.dtd">
<address>
<name> Ravi Kumar </name>
<hno> 7/G, Brindavan Colony </hno>
<city> Karimanagr </city>
<pin> 505001 </pin>
</address>
14. What is Hyperlink? How we can accomplish this using XML? Explain with the help of an
example. (Or) Discuss about the use of Hyperlinks in XML with example.
Creating hyperlink in HTML is very easy. We use the anchor tag ‘<a>’ to create
hyperlinks. The general syntax is shown below.
<a href="url"> Text to act as hyperlink </a>
Example: <a href="www.apoorvacollege.com"> Visit Apoorva </a>
Hyperlinks in XML can be created in many ways. Three different methods are shown
below.
1. Using XLink
2. Using XPointer
3. Using XHTML namespace
1) Using XLink: We can create hyperlinks in an XML document using XLink. With
XLink we can define two types of links: simple links and extended links. Simple links are
links similar to HTML links and extended links are used for linking multiple resources
together.
XML does not use any predefined tags to create hyperlinks. We can use any tag to
create a hyperlink. However, we need to add a little bit of information to the tag to
change it from a normal XML node to an XML hyperlink node. Consider the following
example:
The most important thing to notice in the following program is the usage of the
xmlns element. For XLink the namespace is http://www.w3.org/1999/xlink.
Without this declaration, we cannot use XLink in the document.
It also requires two XLink attributes : xlink:type and xlink:href.
The type element refers to the “type” of the hyperlink (Simple or Extended) and
“href” refers to the location to which this link should navigate to.
To make the hyperlink work we have created “page.xsl” and linked it in the xml
document using <?xml-stylesheet ?> declaration.
test.xml:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="page.xsl" ?>
<page xmlns:xlink="http://www.w3.org/1999/xlink">
<mylink xlink:href="http://www.apoorvacollege.com"
xlink:type="simple"> Visit Apoorva </mylink>
</page>
2) Using XPointer: XPointer also allows us to create hyperlinks. But, this allows us to
navigate to specific parts of an XML document. Sometimes it is useful to navigate to
specific areas of the same page or other pages . In HTML it is possible to do this using
the # character. In XML we can achieve the same by using XPointers. To navigate to a
specific part of a page we need to add a pound sign # and a XPointer expression after
the URL in the xlink:href. Consider the following example. The xml file (test.xml) creates
a link using XLink and XPointer to Smith’s details of the target XML document
“employees.xml”. We also require “xsl” file to make the hyperlink work. The xsl file
“page.xsl” given in the previous section should be used here also.
employees.xml
test.xml
test.xml
<?xml version="1.0" ?>
<?xml-stylesheet type="text/css" href="page.css" ?>
<page xmlns:html="http://www.w3.org/1999/xhtml">
<html:a href="http://www.apoorvacollege.com">
Visit Apoorva
</html:a>
</page>
page.css
Note: Refer to Section 1 & 2 (Using XLink & Using XPointer) in the previous question.
16. Explain Types of Links in XML. (Or) Explain Simple, Extended Links.
Simple Links: Simple links are very much like HTML anchor element <A>, but with
more general reference capabilities. A simple link contains only one link and one target.
Following are the limitations on simple links:
The source of the link is the link element itself
There is only one target
The title is carried by a single attribute
Source
Link Target
Extended links: Extended links generally point to more than one target and from
more than one source. Both sources and targets are called as resources. In fact,
whether a resource is a source or a target can change depending on which link is being
followed and in which direction. Resources are divided into remote resources and local
resources.
A local resource is actually contained inside the extended link element (xlink:type =
“resource”). That is, this type locates a local resource.
A remote resource exists outside the extended link element, possibly in another
document. The extended link element contains locator child elements that point to
the remote resource (xlink:type = “locator”). That is, this type locates a remote
resource.
Extended Links offers the following advanced features:
Multiple sources and targets using xlink:locator elements
Multiple actuation possible using xlink:arc elements
Multiple xlink:title elements
Locator Locator
Link
Locator Locator
<WEBSITE xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:type="extended">
<NAME xlink:type="resource"> Apoorva Downloads Page </NAME>
<HOMESITE xlink:type="locator"
xlink:href="http://www.site1.com/downloads/" />
<MIRROR xlink:type="locator"
xlink:href="http://www.site2.com/downloads /" />
<MIRROR xlink:type="locator"
xlink:href="http://www.site3.com/downloads /" />
</WEBSITE>
Linking Elements: The XLink in XML is more flexible with tags because it creates not
only links but also describe elements. These descriptions may include link behavior,
type, link timing and etc. The different linking elements are identified by an xlink:type
attribute. The xlink:type attribute may take the following values.
Simple: Simple links are very much like HTML anchor element <A>, but with more
general reference capabilities. A simple link contains only one link and one target.
Extended: Extended links are used for linking multiple resources together. They
point to more than one target and from more than one source.
Locator: A locator identifies a remote resource participating in a link. A locator is
possible only with extended links. There is a lcoator for each resource that
participates in an extended link.
Resource: Resource identifies a local resource participating in a link. It is possible
only with extended links. A local resource is actually contained inside the extended
link element
Arc: An arc is information about the origin, destination and behavior of a link
between two resources. The origin and destination resources are defined by labels.
By using one or more arcs, an extended link can achieve specific sets of
connections between multiple resources. It defines a traversal rule between any
combination of two locators and resources.
<mylink xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:href="http://www.apoorvacollege.com"
xlink:type="simple"
xlink:title="More about the college"
B- Com III – Web Programming
184 Apoorva Publishers
xlink:role ="collegeprofile.html">
Visit Apoorva
</mylink>
Link Behavior: Linking elements can contain two optional attributes that suggest to
applications how the link behaves when activated. These are:
xlink:show
xlink:actuate
xlink:show: The xlink:show attribute talks about Link Effects. This attribute suggests
where the content should be displayed on the activation of the link. For example, by
opening a new window to hold the target content or by loading the target into the
current window. The xlink:show attribute has the following five possible values:
Replace: If the value of xlink:show is replace, then when the link is activated by
clicking on it and the target of the link replaces the current document in the same
window. This is the default behavior of links in HTML documents.
New: If the value of xlink:show is new, activating the link opens a new window in
which the targeted resource is displayed. This is similar to the behavior of HTML
links when the target attribute is set to _blank.
Embed: If the value of xlink:show is embed, activating the link inserts the targeted
resource into the existing document. It implies that the application should render
the linked content and display it as part of that document itself. This is how the
IMG, APPLET, and OBJECT elements behave in HTML.
Other: If the value of xlink:show is other, then the application is supposed to look
for other markup in the document that explains what to do. Generally, this would
be used when an XML application uses a non-XLink elements or attributes to
describe the link behavior.
None: We can also set xlink:show to none to indicate that the document contains
no information to help the application decide what to do with the link. It is
completely up to the application reading the document to make its own choices.
Example: The following program uses “replace” value for xlink:show. It suggests that
the target of the lnik should be opened within the same window.
<link xlink:type="simple"
xlink:show="replace"
xlink:href="http://www.apoorvacollege.com">
Visit Apoorva
</link>
Example: The following program uses “onrequest” value for xlink:actuate. It suggests
that the target of the lnik should be opened only when the user clicks on that link.
<link xlink:type="simple"
xlink:show="replace"
xlink:actuate="onrequest"
xlink:href="http://www.apoorvacollege.com">
Visit Apoorva
</link>
Link Timing: Link timing in XML links suggests when the link should be activated. That
is, it may be when the document that contains the link is loaded or when the user clicks
on that and so on. This suggestions can be according to the value of “xlink:actuate”
attribute.
The problem with this is, the xlink:title (a predefined element of xlink) might assume
this “title” as link title and displays this when mouse hovers over the link. To avoid this,
we use attribute remapping.
The xml:attributes attribute lets us remap the attributes used. Its value is a series of
pairs, all separated by spaces. The first item in each pair is the name of an attribute
that an XLink processor expects to find, such as “title” or “role”; the second is the name
of the attribute that we actually used.
In the following example, since “title” is already used as title of the person, we might
want to use the attribute “link-title” as the title for the link. Following example
demonstrates this.
In this case, the xml:attributes attribute says that the title of the link is in the “link-title”
attribute; the browser might display “Mahathma Gandhi Biography” when the mouse
hovers over the link, instead of “Mahathma”.
21. Define XML Parser and explain how to use XML with HTML.
XML Parser: An XML parser converts an XML document into an XML DOM object, which
can then be manipulated using Scripts or other programming languages. A parser does
two things.
1. It reads data from XML files and
2. It makes the information from those files available to other applications and
programming languages.
Using XML with HTML: To use XML data in HTML we use XML Data Source Object
(DSO). It is a Microsoft ActiveX control available with Microsoft Internet Explorer. This
object is a kind of parser that allows us to extract content from an external XML file or
B- Com III - Web Programming
Apoorva Publishers 187
XML data embedded in the HTML file into a HTML page. Using this object, we can
directly make use of XML data in HTML and display as per our requirement. Following is
the syntax used to create XML Data Source Object.
Example: The following html program (test.html) creates XML Data Source Object that
uses data from the XML file “address.xml”. It then prints the data in a table using pure
HTML tags. Note that DATASRC attribute refers to XML DSO name and DATAFLD refers
to the elements of XML file. The output is also shown.
address.xml
<?xml version="1.0" ?>
<person>
<address>
<name> Srinivas </name> <city> Karimanagr </city>
</address>
<address>
<name> Ramu </name> <city> Hyderabad </city>
</address>
<address>
<name> Kiran </name> <city> Warangal </city>
</address>
</person>
test.html
<XML ID="xmldso" src="address.xml"></XML>
<table border=1 DATASRC="#xmldso">
<tr>
<td> <span DATAFLD="name"></span> </td>
<td> <span DATAFLD="city"></span> </td>
</tr>
</table>
Output:
Srinivas Karimanagr
Ramu Hyderabad
Kiran Warangal
22. Write a brief note on XML Document Object Model with an example.
XML DOM: The XML Document Object Model defines a standard way for accessing and
manipulating XML documents. The XML DOM views an XML document as a tree-
According to the DOM, everything in an XML document is a node. The DOM says:
The entire document is a document node
Every XML element is an element node
The text in the XML elements are text nodes
Every attribute is an attribute node
Comments are comment nodes
<bookstore>
<book>
<title lang="en"> DBMS BOOK</title>
<author> Venu </author>
<price> 170 </price>
</book>
</bookstore>
Address.xml
<?xml version="1.0" ?>
<person>
<address>
<name> Srinivas </name> <city> Karimanagr </city>
</address>
<address> <name> Ramu </name> <city> Hyderabad </city>
</address>
<address>
<name> Kiran </name> <city> Warangal </city>
</address>
</person>
Output:
Srinivas Karimanagr
Ramu Hyderabad
Kiran Warangal
XML query language: Query languages are used to fetch information from a database
or a data source. The XML query language is known as XQuery. XQuery is designed to
query XML data, not only XML files, but also a document that can appear as XML,
including databases. XQuery is to XML what SQL is to database tables.
Features of XQuery:
address.xml
<?xml version="1.0" ?>
<person>
<address>
<name> Srinivas </name> <city> Karimanagr </city>
</address>
<address> <name> Ramu </name> <city> Hyderabad </city>
</address>
<address>
<name> Kiran </name> <city> Warangal </city>
</address>
</person>
XQuery: doc("address.xml")/person/address/name
CSS XSL
CSS stands for Cascade Style Sheets. XSL stands for Extensible Stylesheet
Langauge
It is meant to be used with HTML and It is meant to be used with XML. It can
can also be used with XML display, navigate, transform data of an XML
document
The order of elements for display The order of elements for display can be
cannot be changed changed
All elements will be displayed. We can choose the required elements for display
Generated text cannot be added to the Generated text can be added to the
presentation presentation.
An element cannot be processed more An element can be processed more than
than once. once.
CSS is very simple It is complex when compared to CSS
It has no programming constructs It has programming constructs like “if”, “for”
and etc.
B- Com III – Web Programming
192 Apoorva Publishers
XML XSL
XML stands for Extensible Markup XSL stands for Extensible Stylesheet
Language Langauge
Its primary purpose is to facilitate the Its primary purpose is to display, navigate,
sharing of structured data across different transform data of an XML document
information systems
It has no programming constructs It has programming constructs like “if”,
“for” and etc.
XML is a sub set of SGML XSL is a tool used to style XML documents
XSL should be bound (kinked) to XML for XSL refers to the elements of XML to
its display control their display
XML not only uses XSL for its display; It XSL is meant to be used with XML
may also use CSS
It has no programming constructs It has programming constructs like “if”,
“for” and etc.
XML namespaces are used for providing uniquely named elements and attributes in an
XML document. They are defined in a W3C recommendation. An XML instance may
contain element or attribute names from more than one XML vocabulary.
UNIVERSITY
PRACTICAL QUESTION-BANK
(FULLY SOLVED)
HTML Programs 194
<body>
<h2>Welcome to APOORVA </h2>
<pre>
<h3> College Profile </h3>
Apoorva Degree College started in the
year 2000 with a vision to produce Skilled graduates.
<h3> Skill Development </h3>
Having realized the importance of skills to the graduates,
It started implementing skill building programs like
Personality development programs, soft skills training to
all its students.
<h3> Placements </h3>
Since 2007 college stood top in placements in Karimnagar
district. Students of Apoorva placed in top MNCs like
Infosys, TCS, CTS, Wipro and so on. College also achieved
University 5th rank and 6th Ranks.
</pre>
</body>
</html>
<html> Output:
<body> H2O
2 2
H<sub> 2 </sub> O <br> X +Y
X <sup> 2 </sup> + Y <sup> 2 </sup>
</body>
</html>
<html>
<body>
<center> <h2>PERSONAL PROFILE</h2> </center>
<table border=0 >
<tr>
<td> Name : </td>
<td> Kiran </td>
</tr>
<tr>
<td> Date Of Birth: </td>
<td> 12/7/1989 </td>
</tr>
<tr>
<td valign=top> Address: </td>
<td> 7/G <br>
Brindavan Colony <br>
Karimnagar <br>
505001 </td>
</tr>
<tr>
<td> E-mail: </td>
<td> [email protected] </td>
</tr>
<tr>
<td> Cell No: </td>
<td> 9999912345 </td>
</tr>
</table>
Output:
PERSONAL PROFILE
Name : Kiran
Date Of Birth: 12/7/1989
Address: 7/G
Brindavan Colony
Educational Qualifications
Achievements
Strengths
I am a quick learner
Flexible and Hardworking
I am self driven and a go-getter
Computer Skills
6. Write a program to display a table with a Row that spans in three Columns
<html> Output:
<body>
<table border=1> Row spans in 3 columns
<tr> <td colspan=3> Row spans in 3 columns
</td> </tr> One Two Three
<tr> <td> One </td> <td> Two </td> <td> Three
</td> </tr>
</table>
</body>
</html>
<html> Output:
<body>
<h4>With a normal border:</h4>
<table border="1">
<tr>
<td>One</td>
<td>Two</td>
</tr>
<tr>
<td>Three</td>
<td>Four</td>
</tr>
</table>
</body>
</html>
B- Com III – Web Programming
200 Apoorva Publishers
8. Design i) Numbers ii) Letters and iii) Lower case lists Using HTML tags
<html> Output:
<body>
<h4>Numbers List </h4> Numbers List
<OL>
<LI> Apple </LI> 1. Apple
<LI> Mango </LI> 2. Mango
<LI> Banana </LI> 3. Banana
</OL>
<h4>Letters List </h4> Letters List
<OL type="A">
<LI> Apple </LI> A. Apple
<LI> Mango </LI> B. Mango
<LI> Banana </LI> C. Banana
</OL>
<h4>Lower Case Letters List </h4> Lower Case Letters List
<OL type="a">
<LI> Apple </LI> a. Apple
<LI> Mango </LI> b. Mango
<LI> Banana </LI> c. Banana
</OL>
</body>
</html>
9. Design i) DISC bullets and ii) Circle Bullets and using HTML tags
<html> Output:
<body>
<h4>Disc Bullets </h4> Disc Bullets
<UL type="disc">
<LI> Apple </LI> Apple
<LI> Mango </LI> Mango
<LI> Banana </LI> Banana
</UL>
<h4>Circle List </h4> Circle List
<UL type="circle">
<LI> Apple </LI> o Apple
<LI> Mango </LI> o Mango
<LI> Banana </LI> o Banana
</UL>
</body>
</html>
<html>
<html> Time Table
<body>
<h1> Time Table </H1> Time Subject Lecturer
<table border=1 > 9-10 am Maths Kiran
<tr> 10-11 am Computers Ravi
<th> Time </th> <th> Subject </th>
<th> Lecturer </th> 11-12 pm Physics Arun
</tr> 12-1 pm Lunch -
<tr>
1-3 pm Lab -
<td> 9-10 am </td> <td> Maths </td>
<td> Kiran </td>
</tr>
<tr>
<td> 10-11 am </td> <td> Computers </td>
<td> Ravi </td>
</tr>
<tr>
<td> 11-12 pm </td> <td> Physics </td>
<td> Arun </td>
</tr>
<tr>
<td> 12-1 pm </td> <td> Lunch </td>
<td> - </td>
</tr>
<tr>
<td> 1-3 pm </td> <td> Lab </td>
<td> - </td>
</tr>
</table>
</body>
</html>
<html>
<body bgcolor=orange text=blue>
<marquee bgcolor=lavender> WELCOME
TO APOORVA </marquee>
<html>
<body>
<p>This is my first paragraph.</p>
<ilayer name="layer1">
<p> This is the information On the layer </p>
</ilayer>
<p>This is my second paragraph.</p>
</body>
</html>
13. Create a webpage and insert an image with width 500 and height 300 and write a
small paragraph on that image. Give title as Image
<html>
<head> <title> IMAGE </title> </head>
<body>
<img src='apoorva.gif' width=500 height=300
alt="image">
<DIV STYLE="position:absolute; top:250px;
left:20px;">
<font color=blue size=6> Apoorva College
started in the year 2000
<br> and soon it became one of the best
colleges in Telangana region </font>
</DIV>
</body>
</html>
Username:
Password:
15. Create a webpage as shown below, that sends email form. This form sends an email
to gmail.
Name:
yourname
Mail:
yourmail
Comment:
yourcomment
<script language="JavaScript">
function sendMail()
{ var link =
"mailto:[email protected]"
+ "&subject=Comments"
+ "&body=" + f1.t1.value ;
window.location.href = link;
}
</script>
<html>
<head> <title> MAIL FORM DEMO </title> </head>
<body>
<form name="f1" >
<h2> This Form Sends an e-mail to GMAIL <h2>
Name: <BR>
<input type=text value='yourname'> <BR>
Mail: <BR>
<input type=text value='yourmail'> <BR>
Comment: <BR>
<input type=text size=30 name='t1' value="your
comment"> <BR>
<input type=button value='Submit'
onclick="sendMail()">
<html>
<frameset cols="25%,50%,25%">
<frame src='a1.html'>
<frame src='a2.html'>
<frame src='a3.html'>
</frameset>
</html>
<html> Output:
<body>
<OL> 1. Maths
<LI> Maths </LI> 2. Physics
<LI> Physics </LI> 3. Computers
<LI> Computers </LI> 4. English
<LI> English </LI> 5. Telugu
<LI> Telugu </LI>
</OL>
</body>
</html>
a1.html
<body>
<h1>First Document</h1>
</body>
a2.html
<body>
<h1>Second Document</h1>
</body>
main.html
<html>
<frameset rows="50%,50%">
<frame src='a1.html'>
<frame src='a2.html'>
</frameset>
</html>
20. Write HTML code to develop a web page having two frames and fill each frame with
different background colors.
a1.html
<body bgcolor=yellow>
<h1>First Document</h1>
</body>
a2.html
<body bgcolor=moonblue>
<h1>Second Document</h1>
</body>
main.html
<html>
<frameset rows="50%, 50%">
<frame src='a1.html'>
<frame src='a2.html'>
</frameset>
</html>
21. Create a webpage using all attributes of frame and other tags.
a1.html
<body bgcolor=yellow>
<h1>First Document</h1>
</body>
a2.html
<body bgcolor=moonblue>
<h1>Second Document</h1>
</body>
main.html
<html>
<frameset rows="50%, 50%">
<frame src='a1.html' name="f1" frameborder=1 noresize scrolling="yes"
marginheight=10 marginwidth=10>
<frame src='a2.html'>
</frameset>
</html>
VBSCRIPT PROGRMAS
1. Using VBScript display a line of text
<html> Output:
<head>
<script language="VBScript"> sum of 30,40 = 70
<html> Output:
<head>
<title> script programs </title> Script in the body section
</head>
<body>
<script language="VBScript">
document.write "Script in the body section"
</script>
</body>
</html>
17. Using Date and Time functions Display Date and time
ASP PROGRAMS
1. Create a HTML form (response.html) for ASP.
Response.html
<html>
<form name="frm" action="http://localhost/myasp/test.asp">
Name: <input type="text" name="t1" > <BR>
<input type="submit" value="submit">
</form>
</html>
Test.asp
<%
response.write("Hello" & request.querystring("t1"))
%>
Output:
response.asp
<% Output:
response.write ("<h1> Hello </h1>")
response.write ("<b> Hello </b><BR>") Hello
response.write ("<B>Hello </B> <BR>")
response.write ("<I> Hello </I> <BR>")
Hello
response.write ("<U> Hello </U> <BR>") Hello
response.write ("<TT>Hello<TT> <BR>") Hello
response.write ("<strike>Hello</strike> <BR>") Hello
response.write ("<font face='arial'> Hello </font>")
%> Hello
Hello
Hello
Note: To execute the above program type the following line in the browser:
http://localhost/myasp/response.asp
Color.html:
<html>
Test.asp
<%
response.write "Name: " & request.querystring("t1")
response.write "<br> Color: " & request.querystring("c1")
%>
Output:
Colour.asp
<%
response.write "Name: " & request.querystring("name")
response.write "<br> Color: " & request.querystring("color")
%>
5. Write a program using ASP forms with radio buttons and its methods.
Color.asp
<%
c=request.querystring("r1")
if c <> "" then
response.write "<body bgcolor=" & c &
">"
else
response.write "<body>"
end if
%>
<form name="frm" action="http://localhost/myasp/color.asp">
<input type=radio name="r1" value="red" onclick="VBScript:submit" > Red <br>
<input type=radio name="r1" value="yellow" onclick="VBScript:submit"> Yellow <br>
<input type=radio name="r1" value="pink" onclick="VBScript:submit"> pink<br>
</form>
</body>
XML - PROGRAMS
1. Write a letter as Document type definition (DTD)
Letter.dtd
<!ELEMENT letter (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
Letter.xml
<?xml version="1.0"?>
<!DOCTYPE letter SYSTEM "letter.dtd">
<letter>
<to>Ravi</to>
<from>Apoorva</from>
<heading>Reminder</heading>
<body>All the best to your exams</body>
</letter>
Article.xml:
<?xml version="1.0" ?>
<?xml-stylesheet type="text/css" href="article.css" ?>
<article>
<title> Importance of softskills </title>
<author> Kiran </author>
<abstract> This article talks about the importance of the
soft skills in todays' environment
</abstract>
<description>
Softskills are considerably imporatant for today's
youth. They improve one's emotional quotient and one's
performance dramatically...
</description>
<summary>
This article has examined the imporatance
of the softskills ..
</summary>
Article.css:
article {display: block; border:"thin solid blue"; width:500; margin-bottom:20px}
title {color: blue; text-transform:uppercase;font-size:20pt}
abstract, summary {display: block; font-style: italic;}
description {display: block; color: gray; font-weight:bold;}
reference, author {display: block; color: red; font-size: 10pt; margin-left: 20pt;}
Output:
SHORT QUESTIONS
3. What is a Tag?
HTML uses markup tags to describe web pages. HTML markup tags are usually called HTML tags.
HTML tags are keywords surrounded by angle brackets as in <tag-name> HTML tags normally
come in pairs like <tag-name> and </tag-name>.
Tag Description
<b> Defines bold text
<i> Defines italic text
<u> Defines underlined text
<big> Defines big text
<small> Defines small text
<sub> Defines subscripted text
<sup> Defines superscripted text
<tt> Defines teletype text
<strike> Strikes off the text
<blink> Makes the text blinking
<font> Allows us to set font-face, color and size
<center> Aligns the text in center
Tag Description
<div> It defines a division in the document
<p > It defines a paragraph
<pre> Preformatted text, it writes text exactly as it is, including
spaces.
<br> forces the browser to start a new line
<blockquote> Blockquote produces text that is indented in from both
the left and right margins.
<address> This tag is used to enclose information such as "address,
signature and authorship"
<center> Center aligns the text/paragraph
<xmp> Similar to reformatting tag; it also ignores the html code
with in this tag.
<h1>, Generates headings in different sizes
<h2>,..<h6>
Tag Description
<strong> Defines strong text
<em> Defines emphasized text
<ins> Defines inserted text
<del> Defines deleted text
<code> Defines computer code text
<kbd> Defines keyboard text
<samp> Defines sample computer code
<var> Defines a variable
<abbr> Defines an abbreviation
<acronym> Defines an acronym
<address> Defines an address element. This tag is used to enclose information
such as "address, signature and authorship"
<bdo> Defines the text direction
<blockquote> Defines a long quotation. Blockquote produces text that is indented
from both the left and right margins.
<q> Defines a short quotation
<cite> Defines a citation
<dfn> Defines a definition term
Attribute Description
align Specifies the alignment of a table according to surrounding text.
Values can be: left, center, right
bgcolor Specifies the background color for a table
border Specifies the width of the borders around a table
cellpadding Specifies the space between the cell wall and the cell content
cellspacing Specifies the space between cells
width Specifies the width of a table
35. What is <HR> tag? (Or) How do you produce a horizontal ruler?
The <hr> tag creates a horizontal line in an HTML page. The hr element can be used to separate
content in an HTML page. It is an empty i.e. has no closing. Example: <hr width=”100%”>
66. What are Script engines and how they are helpful? Explain.
The script engine implements all the functions and procedures that can be used in script
programs. Without script engine, we cannot execute our script programs. Script engines are
provided by the operating system itself. The browser identifies the language of the script, and
then calls the appropriate scripting engine.
B- Com III - Web Programming
Apoorva Publishers 227
84. What is the statement used in ASP to print text in the browser?
To send output to the browser, we use the following method.
response.write "some text"
101.What is “ADO”?
ADO stands for ActiveX Data Objects
ADO is a Microsoft Active-X component
ADO is automatically installed with Microsoft IIS
ADO is a programming interface to access data in a database
117.What is CDATA?
CDATA means character data. CDATA is text that will NOT be parsed by a parser. Inside the
CDATA tags, the text will NOT be treated as markup and entities will not be expanded. Example:
<statement> <![CDATA[x>y?x:y]]> </statement>
120.What is XSL?
XSL stands for EXtensible Stylesheet Language. The World Wide Web Consortium (W3C) started
to develop XSL because there was a need for an XML-based Stylesheet Language. Though CSS can
be used to format XML documents, W3C recommends XSL to style XML documents.
122.What is DTD?
Document Type Definition (DTD) is a set of markup declarations that define a document type for
markup languages like SGML, XML and HTML. DTD defines the legal building blocks of an XML
document. It defines the document structure with a list of legal elements and attributes.
123.What is XLink?
We can create hyperlinks in an XML document using XLink. With XLink we can define two types
of links: simple links and extended links. Simple links are links similar to HTML links and extended
links are used for linking multiple resources together.
124.What is XPointer?
1. Answer any five of the following questions in not more than one page each.
(a) What is a HTML Frame? (Q.No: 37, P:No:35)
(b) What is Marquee tag? And explain its attributes. (Q.No: 15, P:No: 17)
(c) Define VB Script. (Q.No: 1, P:No: 53)
(d) What is Number Property? (Q.No: 64, P:No: 226)
(e) What is Dynamic HTML? (Q.No: 1, P:No: 98)
(f) What are the ASP Objects? (Q.No: 8, P:No: 138)
(g) What is XSL? (Q.No: 9, P:No: 172)
(h) What is Data Object Model? (Q.No: 22, P:No: 187)
2. (a) Explain the different HTML tags with their attributes: (Q.No: 5,6,7, P:No: 10)
OR
(b) What is a Frame? Explain about it. (Q.No: 37, P:No: 35)
3. (a) Define a variable. Explain its declaring procedure and rules. (Q.No: 6, P:No: 60)
OR
(b) Explain the various control structures in VB script. (Q.No: 10, P:No: 63)
4. (a) What is DHTML? Explain its features. (Q.No: 1, P:No: 98)
OR
:
(b) How do you create multimedia effects with filters and transitions?
(Q.No: 40, P:No: 130)
5. (a) Write about ASP Active Server Pages. (Q.No: 1, P:No: 133)
OR
(b) Explain about Information Search Tools/Index Services. (Q.No: 31, P:No: 162)
6. (a) What is XML? Explain its benefits. (Q.No: 2, P:No: 165)
OR
(b) Discuss the differences between XML and HTML. (Q.No: 24, P:No: 190)
SECTION B- (5 x 10 = 50 marks)
3. (a) Explain different branching control structures in VB Script. (Q.No: 11, P:No: 63)
OR
(b) What are the VB Script dialog boxes (MSGBOX and INPUTBOX)? Discuss.
(Q.No: 33, P:No: 82)
4. (a) Explain the different types of selectors used in style Sheets with examples.
(Q.No: 9, P:No: 103)
OR
(b) What is a filter? Explain the different filters in DHTML. (Q.No: 38, P:No: 126)
6. (a) What is .XML? Write the structure of XML with an example. (Q.No: 4, P:No: 166)
OR
(b) Explain XML Style Sheets. (Q.No: 10, P:No: 173)
SECTION B- (5 x 10 = 50 marks)
Answer the following questions in not more than b pages each.
2. a) Define Marquee tag. Explain its attributes. (Q.No: 15, P:No: 17)
OR
b) Explain Form elements in HTML. (Q.No: 33, P:No: 31)
4. a) Explain Cascading Style Sheets with suitable examples. (Q.No: 3, P:No: 99)
OR
b) Discuss Event Handling in DHTML. (Q.No: 21, P:No: 111)
6. a) Define XML and differentiate between XML,HTML. (Q.No: 24, P:No: 191)
Or
b) Explain about Internal, External Document type definition. (Q.No: 13, P:No: 177)