Web Programming Notes for BCA Students
Web Programming Notes for BCA Students
S.n o : Ti t l e Pa g e n o :
1. H TM L Pr o g r a m m i n g I n t r o d u ct i o n 02 - 03
Fo r m a t t i n g Te x t - Fo r m s & Fo r m u l a t i n g
2. 04 - 12
El e m e n t s
i. Fo r m a t t i n g Te x t 04 - 05
ii. Fo r m a t t i n g Fo r m s 06 - 08
iii. Fo r m u l a t i n g El e m e n t s 09 - 12
Gr a p h i cs i n H TM L Cr e a t i n g Ta b l e s &
3. 13 - 22
Fr a m e s
i. Ta b l e s 13 - 19
ii. Fr a m e s 20 - 22
4. W e b D e si g n Pr i n ci p l e s 23 - 29
5. PROGRA M ES W I TH OUTPUT: 30 - 45
i. H TM L El e m e n t s Fo r m a t t i n g 30 - 30
H TM L Te x t Fo r m a t t i n g
ii. 31 - 33
H TM L Ta b l e s
iii. 34 - 39
iv. H TM L Fr a m e s 40 - 41
H TM L Fo r m s
v. 42 - 45
[Link]
H TM L Pr o g r a m m i n g I n t r o d u ct i o n
HTML, which stands for HyperText Markup Language, is the predominant markup
languagefor web pages. HTML is the basic building-blocks of webpages.
HTML is written in the form of HTML elements consisting of tags, enclosed in angle
brackets(like <html>), within the web page content. HTML tags normally come in pairs
like <h1> and </h1>. The first tag in a pair is the start tag, the second tag is the end
tag (they are also calledopening tags and closing tags). In between these tags web
designers can add text, tables, images, etc.
The purpose of a web browser is to read HTML documents and compose them into
visual or audible web pages. The browser does not display the HTML tags, but uses the
tags to interpret the content of the page.
HTML elements form the building blocks of all websites. HTML allows images and
objects to be embedded and can be used to create interactive forms. It provides a
means to create structured documents by denoting structural semantics for text such as
headings, paragraphs, lists, links, quotes and other items. It can embed scripts in
languages such as JavaScript which affect the behavior of HTML webpages.
Web browsers can also refer to Cascading Style Sheets (CSS) to define the
appearance and layout of text and other material. The W3C, maintainer of both the
HTML and the CSS standards, encourages the use of CSS over explicitly presentational
HTML markup.[1]
What is HTML?
HTML is a language for describing web pages.
HTML Tags
HTML m arkup t ags are usually called HTML t ags
[Link]
The purpose of a web brow ser ( like I nt ernet Explorer or Firefox) is t o read HTML
docum ent s and display t hem as web pages. The brow ser does not display t he HTML
t ags, but uses t he t ags t o int erpret t he cont ent of t he page:
[Link]
Fo r m a t t i n g Te x t - Fo r m s & Fo r m u l a t i n g El e m e n t s –
HTML uses t ags like < b> and < i> for form at t ing out put , like b o l d or it alic t ext .
Oft en < st rong> renders as < b> , and < em > renders as < i> .
< st rong> or < em > m eans t hat you want t he t ext t o be rendered in a w ay t hat t he
user underst ands as " im port ant " . Today, all m aj or browsers render st rong as bold
and em as it alics. However, if a brow ser one day want s t o m ake a t ext highlight ed
wit h t he st rong feat ure, it m ight be cursive for exam ple and not bold!
H TM L Te x t Fo r m a t t i n g Ta g s
[Link]
[Link]
Fo r m a t t i n g Fo r m s-
HTML form s are used t o pass dat a t o a server.
A form can cont ain input elem ent s like t ext fields, checkboxes, radio- but t ons,
subm it but t ons and m ore. A form can also cont ain select list s, t ext area, fieldset ,
legend, and label elem ent s.
<form>
.
input elements
.
</form>
An input elem ent can vary in m any ways, depending on t he t ype at t ribut e. An input
elem ent can be of t ype t ext field, checkbox, password, radio but t on, subm it but t on,
and m ore.
Text Fields
< input t ype= " t ext " / > defines a one- line input field t hat a user can ent er t ext int o:
<form>
First name: <input type="text" name="firstname" /><br />
Last name: <input type="text" name="lastname" />
</form>
[Link]
First nam e:
Last nam e:
N o t e : The form it self is not visible. Also not e t hat t he default widt h of a t ext field is
20 charact ers.
Password Field
< input t ype= " password" / > defines a password field:
<form>
Password: <input type="password" name="pwd" />
</form>
Password:
N o t e : The charact ers in a password field are m asked ( shown as ast erisks or
circles) .
<form>
<input type="radio" name="sex" value="male" /> Male<br />
<input type="radio" name="sex" value="female" /> Female
</form>
Male
Fem ale
[Link]
Checkboxes
< input t ype= " checkbox" / > defines a checkbox. Checkboxes let a user select ONE
or MORE opt ions of a lim it ed num ber of choices.
<form>
<input type="checkbox" name="vehicle" value="Bike" /> I have a
bike<br />
<input type="checkbox" name="vehicle" value="Car" /> I have a
car
</form>
I have a bike
I have a car
Subm it But t on
< input t ype= " subm it " / > defines a subm it but t on.
A subm it but t on is used t o send form dat a t o a server. The dat a is sent t o t he page
specified in t he form 's act ion at t ribut e. The file defined in t he act ion at t ribut e
usually does som et hing wit h t he received input :
Submit
Usernam e:
I f you t ype som e charact ers in t he t ext field above, and click t he " Subm it " but t on,
t he browser will send your input t o a page called " ht m l_form _act [Link]" . The page
will show you t he received input .
[Link]
Fo r m u l a t i n g El e m e n t s-
Elements
Main article: HTML element
HTML documents are composed entirely of HTML elements that, in their most general
form have three components: a pair of tags, a "start tag" and "end tag";
some attributes within the start tag; and finally, any textual and
graphical content between the start and end tags, perhaps including other nested
elements. The HTML element is everything between and including the start and end
tags. Eachtag is enclosed in angle brackets.
The general form of an HTML element is therefore: <tag attribute1="value1"
attribute2="value2">content</tag>. Some HTML elements are defined as empty
elements and take the form <tag attribute1="value1" attribute2="value2" />.
Empty elements may enclose no content. The name of an HTML element is the name
used in the tags. Note that the end tag's name is preceded by a slash character, "/", and
that in empty elements the slash appears just before the closing >. If attributes are not
mentioned, default values are used in each case.
St a r t t a g * El e m e n t co n t e n t En d t a g *
< p> This is a paragraph < / p>
< a href= " default .ht m " > This is a link < / a>
< br / >
[Link]
10
<html>
<body>
<p>This is my first paragraph.</p>
</body>
</html>
The < p> elem ent defines a paragraph in t he HTML docum ent .
The elem ent has a st art t ag < p> and an end t ag < / p> .
The elem ent cont ent is: This is m y first paragraph.
Th e < b o d y > e l e m e n t :
<body>
<p>This is my first paragraph.</p>
</body>
[Link]
11
The < body> elem ent defines t he body of t he HTML docum ent .
The elem ent has a st art t ag < body> and an end t ag < / body> .
The elem ent cont ent is anot her HTML elem ent ( a p elem ent ) .
Th e < h t m l > e l e m e n t :
<html>
<body>
<p>This is my first paragraph.</p>
</body>
</html>
The < ht m l> elem ent defines t he whole HTML docum ent .
The elem ent has a st art t ag < ht m l> and an end t ag < / ht m l> .
The elem ent cont ent is anot her HTML elem ent ( t he body elem ent ) .
<p>This is a paragraph
<p>This is a paragraph
The exam ple above w orks in m ost browsers, because t he closing t ag is considered
opt ional.
Never rely on t his. Many HTML elem ent s will produce unexpect ed result s and/ or
errors if you forget t he end t ag .
< br> is an em pt y elem ent w it hout a closing t ag ( t he < br> t ag defines a line
break) .
Ti p : I n XHTML, all elem ent s m ust be closed. Adding a slash inside t he st art t ag, like
< br / > , is t he proper way of closing em pt y elem ent s in XHTML ( and XML) .
[Link]
12
W3Schools use lowercase t ags because t he World Wide Web Consort ium
( W3C) r e co m m e n d slowercase in HTML 4, and d e m a n d s lowercase t ags in XHTML.
[Link]
13
Gr a p h i cs i n H TM L Cr e a t i n g Ta b l e s & Fr a m e s-
H TM L Ta b l e s:
TA BLES:
A t able is divided int o row s ( w it h t he < t r> t ag) , and each row is divided int o dat a
cells ( wit h t he < t d> t ag) . t d st ands for " t able dat a," and holds t he cont ent of a dat a
cell. A < t d> t ag can cont ain t ext , links, im ages, list s, form s, ot her t ables, et c.
• The less obvious - but more widely used - purpose of creating a page
layout with the use of hidden tables.
Using tables to divide the page into different sections is an extremely powerful
tool.
Almost all major sites on the web are using invisible tables to layout the pages.
The most important layout aspects that can be done with tables are:
• Dividing the page into separate sections.
An invisible table is excellent for this purpose.
• Creating menus.
Typically with one color for the header and another for the links following in
the next lines.
• Adding interactive form fields.
Typically a gray area containing a search option.
[Link]
14
The importance of using tables for these layout purposes can't be overrated.
However there are a few things to keep in mind when doing so.
Most important is, that the content of a table is not shown until the entire table is
loaded. If you have extremely long pages, you should divide it into two or more
tables - allowing the user to start reading the upper content while the rest of the
page is loading.
H TM L < t a b l e > Ta g
Definit ion and Usage
A sim ple HTML t able consist s of t he t able elem ent and one or m ore t r, t h,
and t d elem ent s.
The t r elem ent defines a t able row, t he t h elem ent defines a t able header, and t he
t d elem ent defines a t able cell.
[Link]
15
A m ore com plex HTML t able m ay also include capt ion, col, colgroup, t head, t foot ,
and t body elem ent s.
H TM L < t h > Ta g
Definit ion and Usage
• Header cells - cont ains header inform at ion ( creat ed wit h t he t h elem ent )
• St andard cells - cont ains dat a ( creat ed wit h t he t d elem ent )
H TM L < t r > Ta g
Definit ion and Usage
H TM L < t d > Ta g
Definit ion and Usage
• Header cells - cont ains header inform at ion ( creat ed wit h t he t h elem ent )
• St andard cells - cont ains dat a ( creat ed wit h t he t d elem ent )
H TM L < ca p t i o n > Ta g
Definit ion and Usage
[Link]
16
The < capt ion> t ag m ust be insert ed im m ediat ely aft er t he < t able> t ag. You can
specify only one capt ion per t able. Usually t he capt ion will be cent ered above t he
t able.
H TM L < co l g r o u p > Ta g
Definit ion and Usage
The < colgroup> t ag is used t o group colum ns in a t able for form at t ing.
The < colgroup> t ag is useful for applying st yles t o ent ire colum ns, inst ead of
repeat ing t he st yles for each cell, for each row.
The < colgroup> t ag can only be used inside a t able elem ent .
H TM L < co l > Ta g
The < col> t ag defines at t ribut e values for one or m ore colum ns in a t able.
The < col> t ag is useful for applying st yles t o ent ire colum ns, inst ead of repeat ing
t he st yles for each cell, for each row.
The < col> t ag can only be used inside a t able or a colgroup elem ent .
H TM L < t h e a d > Ta g
Definit ion and Usage
The < t head> t ag is used t o group t he header cont ent in an HTML t able.
The t head elem ent should be used in conj unct ion wit h
t he t body and t foot elem ent s.
The t body elem ent is used t o group t he body cont ent in an HTML t able and t he t foot
elem ent is used t o group t he foot er cont ent in an HTML t able.
N o t e : < t foot > m ust appear before < t body> wit hin a t able, so t hat a browser can
render t he foot before receiving all t he rows of dat a.
Not ice t hat t hese elem ent s will not affect t he layout of t he t able by default .
However, you can use CSS t o let t hese elem ent s affect t he t able's layout .
[Link]
17
H TM L < t b o d y > Ta g
Definit ion and Usage
The < t body> t ag is used t o group t he body cont ent in an HTML t able.
The t body elem ent should be used in conj unct ion wit h
t he t head and t foot elem ent s.
The t head elem ent is used t o group t he header cont ent in an HTML t able and t he
t foot elem ent is used t o group t he foot er cont ent in an HTML t able.
N o t e : < t foot > m ust appear before < t body> wit hin a t able, so t hat a browser can
render t he foot before receiving all t he rows of dat a.
Not ice t hat t hese elem ent s will not affect t he layout of t he t able by default .
However, you can use CSS t o let t hese elem ent s affect t he t able's layout .
H TM L < t f o o t > Ta g
Definit ion and Usage
The < t foot > t ag is used t o group t he foot er cont ent in an HTML t able.
The t foot elem ent should be used in conj unct ion wit h
t he t head and t body elem ent s.
The t head elem ent is used t o group t he header cont ent in an HTML t able and t he
t body elem ent is used t o group t he body cont ent in an HTML t able.
N o t e : < t foot > m ust appear before < t body> wit hin a t able, so t hat a browser can
render t he foot before receiving all t he rows of dat a.
Not ice t hat t hese elem ent s will not affect t he layout of t he t able by default .
However, you can use CSS t o let t hese elem ent s affect t he t able's layout .
<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
[Link]
18
<table border="1">
<tr>
<td>Row 1, cell 1</td>
<td>Row 1, cell 2</td>
</tr>
</table>
All m aj or browsers w ill display t he t ext in t he < t h> elem ent as bold and cent ered.
<table border="1">
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
[Link]
19
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
Head er 1 Head er 2
row 1, cell 1 row 1, cell 2
row 2, cell 1 row 2, cell 2
[Link]
20
H TM L Fr a m e s:
Frames can divide the screen into separate windows.
• make the normal HTML documents that should be loaded into each of
these frames.
Wit h fram es, you can display m ore t han one HTML docum ent in t he sam e brow ser
window. Each HTML docum ent is called a fram e, and each fram e is independent of
t he ot hers.
[Link]
21
The fram eset elem ent st at es HOW MANY colum ns or rows t here will be in t he
fram eset , and HOW MUCH percent age/ pixels of space will occupy each of t hem .
The first colum n is set t o 25% of t he widt h of t he browser window. The second
colum n is set t o 75% of t he widt h of t he browser window. The docum ent
" fram e_a.ht m " is put int o t he first colum n, and t he docum ent " fram e_b.ht m " is put
int o t he second colum n:
N o t e : Add t he < nofram es> t ag for browsers t hat do not support fram es.
I m p o r t a n t : You cannot use t he < body> < / body> t ags t oget her wit h t he
< fram eset > < / fram eset > t ags! However, if you add a < nofram es> t ag cont aining
som e t ext for brow sers t hat do not support fram es, you will have t o enclose t he
t ext in < body> < / body> t ags! See how it is done in t he first exam ple below.
H TM L Fr a m e Ta g s
Ta g D e scr i p t i o n
< fram eset > Defines a set of fram es
< fram e / > Defines a sub window ( a fram e)
< nofram es> Defines a nofram e sect ion for browsers t hat do not handle fram es
[Link]
22
H TM L < f r a m e se t > Ta g
Definit ion and Usage
The fram eset elem ent holds one or m ore fram e elem ent s. Each fram e elem ent can
hold a separat e docum ent .
The fram eset elem ent st at es HOW MANY colum ns or rows t here will be in t he
fram eset , and HOW MUCH percent age/ pixels of space will occupy each of t hem .
H TM L < f r a m e > Ta g
Definit ion and Usage
The < fram e> t ag defines one part icular w indow ( fram e) w it hin a fram eset .
Each fram e in a fram eset can have different at t ribut es, such as border, scrolling,
t he abilit y t o resize, et c.
H TM L < n o f r a m e s> Ta g
Definit ion and Usage
The < nofram es> t ag is used for brow sers t hat do not handle fram es.
The nofram es elem ent can cont ain all t he elem ent s t hat you can find inside t he
body elem ent of a norm al HTML page.
The nofram es elem ent is m ost used t o link t o a non- fram eset version of t he web
sit e or t o display a m essage t o users t hat fram es are required.
The nofram es elem ent goes inside t he fram eset elem ent .
[Link]
23
W e b D e si g n Pr i n ci p l e s-
Web design is a broad term used to encompass the way
that content (usually hypertext or hypermedia) is delivered to an end-user through
the World Wide Web, using a web browser or other web-enabled software to display the
content. The intent of web design is to create awebsite—a collection of online content
including documents and applications that reside on a web server/servers. A website
may include text, images, sounds and other content, and may be interactive.
[Link]
24
2. Spacing
When I first started designing I wanted to fill every available space up with stuff. Empty
space seemed wasteful. In fact the opposite is true.
Spacing makes things clearer. In Web design there are three aspects of space that you
should be considering:
• Line Spacing
When you lay text out, the space between the lines directly affects how readable it
appears. Too little space makes it easy for your eye to spill over from one line to the
next, too much space means that when you finish one line of text and go to the next your
eye can get lost. So you need to find a happy medium. You can control line spacing in
CSS with the ‘line-height’ selector. Generally I find the default value is usually too little
spacing. Line Spacing is technically called leading (pronounced ledding), which derives
from the process that printers used to use to separate lines of text in ye olde days — by
placing bars of lead between the lines.
• Padding
Generally speaking text should never touch other elements. Images, for example, should
not be touching text, neither should borders or tables.
Padding is the space between elements and text. The simple rule here is that you
should always have space there. There are exceptions of course, in particular if the text
is some sort of heading/graphic or your name is David Carson But as a general rule,
putting space between text and the rest of the world makes it infinitely more readable
and pleasant.
• White Space
First of all, white space doesn’t need to be white. The term simply refers to empty space
on a page (or negative space as it’s sometimes called). White space is used to give
balance, proportion and contrast to a page. A lot of white space tends to make things
seem more elegant and upmarket, so for example if you go to an expensive architect site,
you’ll almost always see a lot of space. If you want to learn to use whitespace
effectively, go through a magazine and look at how adverts are laid out. Ads for big
brands of watches and cars and the like tend to have a lot of empty space used as an
element of design.
[Link]
25
3. Navigat ion
One of the most frustrating experiences you can have on a Web site is being unable to
figure out where to go or where you are. I’d like to think that for most Web designers,
navigation is a concept we’ve managed to master, but I still find some pretty bad
examples out there. There are two aspects of navigation to keep in mind:
Navigation — Where can you go?
There are a few commonsense rules to remember here. Buttons to travel around a site
should be easy to find – towards the top of the page and easy to identify. They should
look like navigation buttons and be well described. The text of a button should be pretty
clear as to where it’s taking you. Aside from the common sense, it’s also important to
make navigation usable. For example, if you have a rollover sub-menu, ensuring a person
can get to the sub-menu items without losing the rollover is important. Similarly
changing the color or image on rollover is excellent feedback for a user.
Orientation — Where are you now?
There are lots of ways you can orient a user so there is no excuse not to. In small sites, it
might be just a matter of a big heading or a ‘down’ version of the appropriate button in
your menu. In a larger site, you might make use of bread crumb trails, sub-headings and a
site map for the truly lost.
4. Design t o Build
Life has gotten a lot easier since Web designers transitioned to CSS layouts, but even
now it’s still important to think about how you are going to build a site when you’re still
in Photoshop. Consider things like:
• Can it actually be done?
You might have picked an amazing font for your body copy, but is it actually a standard
HTML font? You might have a design that looks beautiful but is 1100px wide and will
result in a horizontal scroller for the majority of users. It’s important to know what can
and can’t be done, which is why I believe all Web designers should also build sites, at
least sometimes.
• What happens when a screen is resizes?
Do you need repeating backgrounds? How will they work? Is the design centered or left-
aligned?
[Link]
26
5. Typogr aphy
Text is the most common element of design, so it’s not surprising that a lot
of thought has gone into it. It’s important to consider things like:
• Font Choices — Different types of fonts say different things about a design. Some look
modern, some look retro. Make sure you are using the right tool for the job.
• Font sizes —Years ago it was trendy to have really small text. Happily, these days
people have started to realize that text is meant to be read, not just looked at. Make sure
your text sizes are consistent, large enough to be read, and proportioned so that headings
and sub-headings stand out appropriately.
• Spacing — As discussed above, spacing between lines and away from other objects is
important to consider. You should also be thinking about spacing between letters,
though on the Web this is of less importance, as you don’t have that much control.
• Line Length — There is no hard and fast rule, but generally your lines of text shouldn’t
be too long. The longer they are, the harder they are to read. Small columns of text work
much better (think about how a newspaper lays out text).
[Link]
27
• Color — One of my worst habits is making low-contrast text. It looks good but doesn’t
read so well, unfortunately. Still, I seem to do it with every Web site design I’ve ever
made, tsk tsk tsk.
• Paragraphing — Before I started designing, I loved to justify the text in everything. It
made for nice edges on either side of my paragraphs. Unfortunately, justified text tends
to create weird gaps between words where they have been auto-spaced. This isn’t nice
for your eye when reading, so stick to left-aligned unless you happen to have a magic
body of text that happens to space out perfectly.
6. Usabilit y
Web design ain’t just about pretty pictures. With so much information and interaction to
be effected on a Web site, it’s important that you, the designer, provide for it all. That
means making your Web site design usable.
We’ve already discussed some aspects of usability – navigation, precedence, and text.
Here are three more important ones:
• Adhering to Standards
There are certain things people expect, and not giving them causes confusion. For
example, if text has an underline, you expect it to be a link. Doing otherwise is not good
usability practice. Sure, you can break some conventions, but most of your Web site
should do exactly what people expect it to do!
• Think about what users will actually do
Prototyping is a common tool used in design to actually ‘try’ out a design. This is done
because often when you actually use a design, you notice little things that make a big
difference. ALA had an article a while back called Never Use a Warning When You
Mean Undo, which is an excellent example of a small interface design decision that can
make life suck for a user.
• Think about user tasks
When a user comes to your site what are they actually trying to do? List out the different
types of tasks people might do on a site, how they will achieve them, and how easy you
want to make it for them. This might mean having really common tasks on your
homepage (e.g. ‘start shopping’, ‘learn about what we do,’ etc.) or it might mean
ensuring something like having a search box always easily accessible. At the end of the
[Link]
28
day, your Web design is a tool for people to use, and people don’t like using annoying
tools!
7. Alignm ent
Keeping things lined up is as important in Web design as it is in print design. That’s not
to say thateverything should be in a straight line, but rather that you should go through and
try to keep things consistently placed on a page. Aligning makes your design more
ordered and digestible, as well as making it seem more polished.
You may also wish to base your designs on a specific grid. I must admit I don’t do this
consciously – though obviously a site like Psdtuts+ does in fact have a very firm grid
structure. This year I’ve seen a few really good articles on grid design including
SmashingMagazine’s Designing with Grid-Based Approach & A List Apart’s Thinking
Outside The Grid. In fact, if you’re interested in grid design, you should definitely pay a
visit to the aptly named [Link] home to all things griddy.
8. Clarity ( Sharpness)
Keeping your design crisp and sharp is super important in Web design. And when it
comes to clarity, it’s all about the pixels.
In your CSS, everything will be pixel perfect so there’s nothing to worry about, but in
Photoshop it is not so. To achieve a sharp design you have to:
• Keep shape edges snapped to pixels. This might involve manually cleaning up shapes,
lines, and boxes if you’re creating them in Photoshop.
• Make sure any text is created using the appropriate anti-aliasing setting. I use ‘Sharp’ a
lot.
9. Consist ency
Consistency means making everything match. Heading sizes, font choices, coloring,
button styles, spacing, design elements, illustration styles, photo choices, etc. Everything
should be themed to make your design coherent between pages and on the same page.
[Link]
29
[Link]
30
PROGRAMES OF UNIT - I
HTML Elem ent s
PROGRAM OUTPUT
H TM L H e a d i n g s This is heading 1
<html>
<body> This is heading 2
<h1>This is heading 1</h1>
<h2>This is heading 2</h2> This is heading 3
<h3>This is heading 3</h3>
<h4>This is heading 4</h4> This is heading 4
<h5>This is heading 5</h5>
<h6>This is heading 6</h6> This is heading 5
</body>
This is heading 6
</html>
H TM L Pa r a g r a p h s
<html>
<body> This is a paragraph.
<p>This is a paragraph.</p>
<p>This is a paragraph.</p> This is a paragraph.
<p>This is a paragraph.</p>
</body>
This is a paragraph.
</html>
H TM L Li n k s
<html>
<body> This is a link
<a href="[Link]
This is a link</a>
</body>
</html>
H TM L I m a g e s
<html>
<body>
<img src="[Link]" width="104"
height="142" />
</body>
</html>
[Link]
31
[Link]
32
Definition term
H TM L " Co m p u t e r Ou t p u t " Ta g s Sample computer code text
<html> Keyboard text
<body> Variable
<dfn>Definition term</dfn><br /> Citation
<samp>Sample computer code
text</samp><br />
<kbd>Keyboard text</kbd><br />
<var>Variable</var><br />
<cite>Citation</cite>
</body>
</html>
Text in a pre element
is displayed in a fixed-width
H TM L < p r e > Ta g font, and it preserves
<html> both spaces and
<body> line breaks
<pre>
Text in a pre element The pre element is often used to display
is displayed in a fixed-width computer code:
font, and it preserves
both spaces and for i = 1 to 10
line breaks print i
</pre> next i
<p>The pre element is often used to display
computer code:</p>
<pre>for i = 1 to 10
print i
next i
</pre>
</body>
</html>
H TM L Ci t a t i o n s, Qu o t a t i o n s, a n d
D e f i n i t i o n Ta g s
<html>
<body> The WHO was founded in 1948.
The <abbr title="World Health Can I get this ASAP?
Organization">WHO</abbr> was founded in Written by [Link]
1948.<br> Email us
Can I get this <acronym title="as soon as
possible">ASAP</acronym>?<br>
Address: Box 564, Disneyland
<address> Phone: +12 34 56 78
Written by [Link]<br /> Here is some Hebrew text that should be
<a href="[Link] written from right-to-left!
[Link]
33
[Link]
34
HTML Tables
Program Output
<html>
<body>
<table border="1">
<tr> Month Savings
<th>Month</th> January $100
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
</table>
</body>
</html>
[Link]
35
H TM L < ca p t i o n > Ta g
<html> Monthly savings
<body>
<table border="1"> Month Savings
<caption>Monthly savings</caption> January $100
<tr>
<th>Month</th> February $50
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$50</td>
</tr>
</table>
</body>
</html>
H TM L < co l g r o u p > Ta g
<html> ISBN Title Price
<body> 3476896 My first HTML $53
<table width="100%" border="1"> 2489604 My first CSS $47
<colgroup span="2" align="left"></colgroup>
<colgroup align="right"
style="color:#0000FF;"></colgroup>
<tr>
<th>ISBN</th>
<th>Title</th>
<th>Price</th>
</tr>
<tr>
<td>3476896</td>
<td>My first HTML</td>
<td>$53</td>
</tr>
<tr>
<td>2489604</td>
<td>My first CSS</td>
<td>$47</td>
</tr>
</table>
</body>
</html>
[Link]
36
H TM L < co l > Ta g
<html>
<body>
<table width="100%" border="1">
<col align="left" /> ISBN Title Price
<col align="left" /> 3476896 My first HTML $53
<col align="right" /> 2489604 My first CSS $47
<tr>
<th>ISBN</th>
<th>Title</th>
<th>Price</th>
</tr>
<tr>
<td>3476896</td>
<td>My first HTML</td>
<td>$53</td>
</tr>
<tr>
<td>2489604</td>
<td>My first CSS</td>
<td>$47</td>
</tr>
</table>
</body>
</html>
H TM L < t h e a d > Ta g
<html>
<head>
<style type="text/css">
thead {color:green}
tbody {color:blue;height:50px}
tfoot {color:red} Month Savings
</style>
</head>
<body> Sum $180
<table border="1">
<thead> January $100
<tr>
February $80
<th>Month</th>
<th>Savings</th>
</tr>
</thead>
<tfoot>
<tr>
<td>Sum</td>
<td>$180</td>
[Link]
37
</tr>
</tfoot>
<tbody>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</tbody>
</table>
</body>
</html>
[Link]
38
H TM L < t b o d y > Ta g
<html>
<head>
<style type="text/css">
thead {color:green}
tbody {color:blue;height:50px}
tfoot {color:red}
</style>
</head> Month Savings
<body>
<table border="1"> Sum $180
<thead>
<tr>
<th>Month</th> January $100
<th>Savings</th> February $80
</tr>
</thead>
<tfoot>
<tr>
<td>Sum</td>
<td>$180</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</tbody>
</table>
</body>
</html>
H TM L < t f o o t > Ta g
<html> Month Savings
<head>
<style type="text/css"> Sum $180
thead {color:green}
tbody {color:blue;height:50px}
tfoot {color:red} January $100
</style> February $80
</head>
<body>
[Link]
39
<table border="1">
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
</thead>
<tfoot>
<tr>
<td>Sum</td>
<td>$180</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</tbody>
</table>
</body>
</html>
[Link]
40
H TM L < Ve r t i ca l f r a m e se t > Ta g
<html>
<frameset cols="25%,50%,25%">
<frame src="frame_a.htm" />
<frame src="frame_b.htm" />
<frame src="frame_c.htm" />
</frameset>
</html>
H TM L < f r a m e se t i n r o w s & co l u m s> Ta g
<html>
<frameset rows="50%,50%">
<frame src="frame_a.htm" />
<frameset cols="25%,75%">
<frame src="frame_b.htm" />
<frame src="frame_c.htm" />
</frameset>
</frameset>
</html>
[Link]
41
H TM L < n o f r a m e s> Ta g
<html>
<frameset cols="25%,50%,25%">
<frame src="frame_a.htm" />
<frame src="frame_b.htm" />
<frame src="frame_c.htm" />
<noframes>
Sorry, your browser does not handle
frames!
</noframes>
</frameset>
</html>
H TM L < n a v i g a t i o n f r a m e se t > Ta g
<html>
<frameset cols="120,*">
<frame src="tryhtml_contents.htm" />
<frame src="frame_a.htm"
name="showframe" />
</frameset>
</html>
[Link]
42
HTML Form s:
Program Output
TEXT FIELD
First name:
<html>
<body> Last name:
<form action="">
First name: <input type="text" Note: The form itself is not visible. Also
name="firstname" /><br /> note that the default width of a text field is
Last name: <input type="text" 20 characters.
name="lastname" />
</form>
<p><b>Note:</b> The form itself is not
visible. Also note that the default width of a
text field is 20 characters.</p>
</body>
</html>
PASSWORD FIELD
<html>
Username:
<body>
<form action=""> Password:
Username: <input type="text" name="user"
/><br /> Note: The characters in a password field are
Password: <input type="password" masked (shown as asterisks or circles).
name="password" />
</form>
<p><b>Note:</b> The characters in a
password field are masked (shown as
asterisks or circles).</p>
</body>
</html>
CHECKBOXES
<html>
I have a bike
<body>
<form action=""> I have a car
<input type="checkbox" name="vehicle"
value="Bike" /> I have a bike<br />
<input type="checkbox" name="vehicle"
value="Car" /> I have a car
</form>
</body>
</html>
RADIO BUTTONS
<html>
Male
<body>
<form action=""> Female
[Link]
43
[Link]
44
Create a Button
<html>
<body>
<form action="">
<input type="button" value="Hello
world!">
</form>
</body>
</html>
Draw a border around form-data
<html>
<body>
<form action="">
<fieldset>
<legend>Personal information:</legend>
Name: <input type="text" size="30" /><br
/>
E-mail: <input type="text" size="30" /><br
/>
Date of birth: <input type="text" size="10"
/>
</fieldset>
</form>
</body>
</html>
[Link]
45
KNOWLEDGE IS POWER
[Link] SALMAN
AVANTHI DEGREE COLLEGE
[Link]
[Link]
[Link] COMPUTER – III YEAR
2011-2012
[Link]
I N D EX – UN I T - I I
S.n o : Ti t l e Pa g e N o :
1 M e a n i n g Of D H TM L 02 - 02
2 Co m p a r i so n b e t w e e n H TM L a n d D H TM L 03 - 03
3 St a t i c a n d D y n a m i c 04 - 04
4 Pr o ce d u r a l a n d N o n Pr o ce d u r a l 05 - 05
5 Ca sca d i n g St y l e Sh e e t s ( CSS) 06 - 06
6 D o cu m e n t Ob j e ct M o d e l ( D OM ) 07 - 08
D i f f e r e n t Ty p e s o f Er r o r s, Ru n t i m e Er r o r s,
7 09 - 10
Sy st e m Er r o r s e t c.,
8 PROGRA M ES W I TH OUTPUT: 11 - 14
i D y n a m i c Ch a n g e s St y l e 11 - 11
ii Te x t 11 - 12
iii Cr e a t i n g Gr a p h i cs & M u l t i m e d i a Ef f e ct s 13 - 14
[Link]
M e a n i n g Of D H TM L
Dynamic HTML (DHTML) is a name for a set of technologies that Web developers can
use to create Web pages that update themselves on the fly. In a Web page
implemented in DHTML, fonts, positions of elements, graphics might change as you
look at it in a browser. Dynamic HTML makes your Web documents more interactive.
Just as in "regular" HTML, when a user downloads a page written in DHTML, the
content is stored on the user's computer for viewing in the browser. In DHTML, this
content might also contain instructions for how changes should take place in the
presentation of the page. Dynamic HTML therefore happens on the client-side. It
doesn't involve reconnecting to the server for more information.
Dynamic HTML is used in conjunction with Cascading Style Sheets (CSS). Using
coordinate positioning available in CSS, a Web developer can place HTML elements in
specific locations on a page. The HTML elements positioned this way can move
according to a script (written in, for example, ActiveX using VBScript; or JavaScript) as
the user views the page. This positioning can occur not only on the X-Y (flat plane) of
the Web page, but in the Z direction, giving the illusion of depth or the stacking of one
element on top of another.
Dynamic HTML relates to the W3C's broader efforts to create an interface called
the Document Object Model (DOM). The aim of DOM is to allow programmers to
dynamically update the content, structure, and style of documents.
[Link]
Co m p a r i so n b e t w e e n H TM L a n d D H TM L
H TM L
HTML st ands for Hyper Text Markup Language,HTML is not a program m ing
language, it is a m arkup language, A m arkup language is a set of m arkup t ags
HTML uses m arkup t ags t o describe web pages
HTML docum ent s describe web pages, cont ain HTML t ags and plain t ext
HTML docum ent s are also called web pages
D H TM L
To m ost people DHTML m eans t he com binat ion of HTML, JavaScript , DOM, and
CSS.
Dynam ic HTML is a collect ive t erm for a com binat ion of new Hypert ext Markup Language
( HTML) t ags and opt ions, t hat will let you creat e Web pages m ore anim at ed and m ore
responsive t o user int eract ion t han previous versions of HTML. Much of dynam ic HTML is
specified in HTML 4.0. Sim ple exam ples of dynam ic HTML pages would include ( 1) having
t he color of a t ext heading change when a user passes a m ouse over it or ( 2) allowing a
user t o " drag and drop" an im age t o anot her place on a Web page. Dynam ic HTML can allow
Web docum ent s t o look and act like deskt op applicat ions or m ult im edia product ions.
[Link]
St a t i c a n d D y n a m i c
DHTML allows scripting languages to change variables in a web page's definition language,
which in turn affects the look and function of otherwise "static" HTML page content, after the
page has been fully loaded and during the viewing process. Thus the dynamic characteristic of
DHTML is the way it functions while a page is viewed, not in its ability to generate a unique
page with each page load.
By contrast, a dynamic web page is a broader concept — any web page generated differently
for each user, load occurrence, or specific variable values. This includes pages created by
client-side scripting, and ones created by server-side scripting (such
as PHP, Perl, JSP or [Link]) where the web server generates content before sending it to
the client.
• The easiest difference is static HTML once rendered cannot be changed on the other
hand dynamic HTML can be changed.
• Static web pages cannot have database access but dynamic pages can be connected to
database.
• Using static HTML no interactions persist between user and server but dynamic HTML
has capability to interact with the user.
• Static HTML does not require server side coding but dynamic HTML requires server side
coding.
• No animation, games can be developed using the static HTML but on the other hand
dynamic HTML can perform this task.
Scripting Languages
Scripts that are executed when a document is loaded may be able to modify the document's
contents dynamically. The ability to do so depends on the scripting language itself (e.g., the
"[Link]" statement in the HTML object model supported by some vendors). JavaScript
is often used to create dynamic HTML documents. One of the more practical things JavaScript
does is allow you to add user events to static pages. For example, JavaScript allows you to
embed statements into a page which allow user response to certain common events such as
when you hover over a link.
The following example illustrates how scripts may modify a document dynamically. The
following script:
<SCRIPT type="text/javascript">
[Link]("<b>Date:<\/b> ")
[Link](Date())
</SCRIPT>
[Link]
Pr o ce d u r a l a n d N o n Pr o ce d u r a l
Pr o ce d u r a l l a n g u a g e s:
Most widely used are BASIC, COBOL, and C Uses series of English-like
words to write instructions Often called third-generation language (3GL) Programmer
assigns name to sequence of instructions that tells computer what to accomplish and
how to do it .
N o n Pr o ce d u r a l l a n g u a g e
Popular 4GL is SQL, query language that allows users to manage data in relational
DBMS
[Link]
Ca sca d i n g St y l e Sh e e t s ( CSS)
Cascading Style Sheets (CSS) is a style sheet language used to describe
the presentation semantics (the look and formatting) of a document written in a markup
language. Its most common application is to style web pages written
in HTML and XHTML, but the language can also be applied to any kind
of XML document, including plain XML, SVG and XUL.
W h a t i s CSS
St y l e s So l v e d a Bi g Pr o b l e m
• HTML was never int ended t o cont ain t ags for form at t ing a docum ent .
• HTML was int ended t o define t he cont ent of a docum ent , like:
• < h1> This is a heading< / h1>
• < p> This is a paragraph.< / p>
• When t ags like < font > , and color at t ribut es were added t o t he HTML 3.2
specificat ion, it st art ed a night m are for web developers. Developm ent of large web
sit es, where font s and color inform at ion were added t o every single page, becam e a
long and expensive process.
• To solve t his problem , t he World Wide Web Consort ium ( W3C) creat ed CSS.
• I n HTML 4.0, all form at t ing could be rem oved from t he HTML docum ent , and st ored
in a separat e CSS file.
• All browsers support CSS t oday.
[Link]
D o cu m e n t Ob j e ct M o d e l ( D OM )
W h a t i s t h e D OM
The DOM defines a standard for accessing documents like HTML and XML:
"The W3C Document Object Model (DOM) is a platform and language-neutral interface
that allows programs and scripts to dynamically access and update the content,
structure, and style of a document."
The DOM defines the objects and properties of all document elements, and
the methods (interface) to access them.
[Link]
W h a t i s t h e H TM L D OM
The HTML DOM defines the objects and properties of all HTML elements, and
the methods(interface) to access them.
In other words: The HTML DOM is a standard for how to get, change, add, or delete
HTML elements.
H TM L D OM EXA M PLE:
PROGRA M OUTPUT
<html> Hello World!
<body>
<script type="text/javascript">
[Link]("Hello World!");
</script>
</body>
</html>
W h a t i s t h e XM L D OM
The XML DOM defines the objects and properties of all XML elements, and
the methods (interface) to access them.
XM L D OM EXA M PLE:
PROGRA M OUTPUT
<html> Everyday Italian
<body>
<script type="text/javascript" src="[Link]"></script> Giada De
</head> Laurentiis
<body> 2005
<script type="text/javascript">
xmlDoc=loadXMLDoc("[Link]");
[Link]([Link]("title")[0].childNodes[0].nodeValue +
"<br />");
[Link]([Link]("author")[0].childNodes[0].nodeValue +
"<br />");
[Link]([Link]("year")[0].childNodes[0].nodeValue);
</script>
</body>
</html>
[Link]
D i f f e r e n t Ty p e s o f Er r o r s, Ru n t i m e Er r o r s, Sy st e m Er r o r s
e t c.,
When creating scripts and web applications, error handling is an important part. If your
code lacks error checking code, your program may look very unprofessional and you
may be open to security risks.
• Compile-time errors
• Logical errors
• Run-time errors
• Generated errors
A compile-time error, for example a syntax error, should not cause much trouble as it is
caught by the compiler.
A logical error is when a program does not behave as intended, but does not crash. An
example could be that nothing happens when a button in a graphical user interface is
clicked.
A generated error is when the code itself calls exit/1 or throw/1. Note that emulated run-
time errors are not denoted as generated errors here.
When a run-time error or generated error occurs in Erlang, execution for the process
which evaluated the erroneous expression is stopped. This is referred to as a failure,
that execution or evaluation fails, or that the process fails, terminates or exits. Note
that a process may terminate/exit for other reasons than a failure.
A process that terminates will emit an exit signal with an exit reason that says
something about which error has occurred. Normally, some information about the error
will be printed to the terminal.
[Link]
10
Ru n - t i m e e r r o r s
Run-time errors are generated when execution of a particular code statement or
function results in an error condition being set. Run-time errors caught by PowerBASIC
include Disk access violations (i.e., trying to write data to a full disk), out of bounds
array and pointer access, and Memory allocation failures. Array bounds and null-
pointer checking is only performed when #DEBUG ERROR ON is used.
Run-time errors can be trapped; that is, you can cause a designated error-handling
subroutine to get control should an error occur. Use the ON ERROR statement to
accomplish this. This routine can "judge" what to do next based on the type of error
that occurs. File-system errors (for example, disk full) in particular are prime
candidates for run-time error-handling routines. They are the only errors that a
thoroughly debugged program should have to deal with.
The ERROR statement (which simulates run-time errors) can be used to debug your
error-handling routines. It allows you to deliberately cause an error condition to be
flagged. Avoid using error numbers higher than 240, as they are reserved for use in
critical error situations which can never be trapped with ON ERROR. Run-time error
values are restricted to the range 1 through 255, and the compiler reserves codes 0
through 150, and 241 through 255 for predefined errors. Attempting to set an error
value (with the ERROR statement) outside of the valid range 1 to 255 will result in a
run-time Error 5 ("Illegal function call") instead. In addition to the predefined run-time
errors, you may also set your own customized run-time error codes in the range 151
through 240. These error codes may be useful to signal specific types of errors in your
own applications, ready to be handled by your error trapping code.
In the situation where an undocumented run-time error occurs, the chief suspect is
memory corruption. This can typically be cause by writing beyond an array boundary,
improper use of pointers, bad Inline Assembly code, etc.
Handling of Run-Time Errors in Erlang
It is possible to prevent run-time errors and other exceptions from causing the process
to terminate by using catch or try, see the Expressions chapter about Catch and Try.
Processes can monitor other processes and detect process terminations, see
theProcesses chapter.
[Link]
11
PROGRAMES OF UNIT - II
D y n a m i c Ch a n g e s St y l e
PROGRA M OUTPUT
Change Style of the Current DHTML Element
<html>
<body> Click Me!
<h1 onclick="[Link]='red'">Click Me!</h1>
</body>
</html> Click Me!
( Click on t ext t o change color)
Change Style of a Specific CSS Element
<html> Click Me!
<body>
<h1 id="h1"
onclick="[Link]('h1').[Link]=' Click Me!
red'">Click Me!</h1> ( Click on t ext t o change color)
</body>
</html>
Ch a n g i n g t e x t :
PROGRA M OUTPUT
<html>
<body>
<h1 id="header">Old Header</h1> New Header
<script type="text/javascript">
[Link]("header").innerHTML="N "Old Header" was changed to
ew Header"; "New Header"
</script>
<p>"Old Header" was changed to "New Header"</p>
</body>
</html>
<html> Mouse over this text!
<head>
<script type="text/javascript">
function nameon() How are you today?
{
[Link]('h2text').innerHTML="WE
LCOME!";
WELCOME!
}
function nameout() ( Click on t ext t o change t ext )
{
[Link]
12
[Link]('h2text').innerHTML="Ho
w are you today?";
}
</script>
</head>
<body>
<h2 id="h2text" onmouseout="nameout()"
onmouseover="nameon()">
Mouse over this text!</h2>
</body>
</html>
<html>
<head>
<script type="text/javascript"> Blinking header
function blinking_header()
{
if (.[Link]) Blinking header
{
[Link]('blink').[Link]= ( Click on t ext t o blink t ext in
"red"; red color)
}
if
([Link]('blink').[Link]=="red"
)
{
[Link]('blink').[Link]=
"black";
}
else
{
[Link]('blink').[Link]=
"red";
}
timer=setTimeout("blinking_header()",100);
}
function stoptimer()
{
clearTimeout(timer);
}
</script>
</head>
<body onload="blinking_header()"
onunload="stoptimer()">
<h1 id="blink">Blinking header</h1>
</body>
</html>
[Link]
13
Cr e a t i n g Gr a p h i cs a n d M u l t i m e d i a Ef f e ct s:
PROGRA M OUTPUT
<html> When you mouse over the
<head> image, a new image will
<script type="text/javascript"> appear.
img2=new Image();
[Link]="[Link]";
function changeImage()
{
[Link]('myImage').src=[Link];
}
</script>
</head>
<body> The new image appears
<p>When you mouse over the image, a new image instantly, because your browser
will appear.</p> has already loaded the image
<img id="myImage" onmouseover="changeImage()"
border="0" width="160" height="120"
src="[Link]">
<p>The new image appears instantly, because your
browser has already loaded the image.</p>
</body>
</html>
<html>
<head>
<script type="text/javascript"> Move the cursor over this
function cursor(event) page
{
[Link]('trail').[Link]="visible" (Move your cursor on output
; window to show cursor text)
[Link]('trail').[Link]="absolute
";
[Link]('trail').[Link]=[Link]
+10;
[Link]('trail').[Link]=[Link];
}
</script>
</head>
<body onmousemove="cursor(event)">
<h1>Move the cursor over this page</h1>
<span id="trail" style="visibility:hidden">Cursor
Text</span>
</body>
</html>
[Link]
14
[Link]
I N D EX – UN I T – I I I A N D I V
S.n o : Ti t l e Pa g e n o :
1. VB Scr i p t i n g I n t r o d u ct i o n 02 - 02
2. VB Scr i p t 02 - 02
3. Ba si cs o f VB Scr i p t 03 - 07
4. Ar r ay Han d lin g 08 - 10
5. Use r I n t e r a ct i o n i n VB Scr i p t 11 - 11
6. H a n d l i n g Ru n t i m e Er r o r s. 12 - 16
7. PROGRA M ES W I TH OUTPUT: 17 - 17
[Link]
VB Scr i p t i n g I n t r o d u ct i o n
What You Should Already Know
Before you continue you should have a basic understanding of the following:
• HTML / XHTML
If you want to study these subjects first, find the tutorials on our Home page.
What is VBScript?
When a VBScript is inserted into an HTML document, Internet Explorer browser will
read the HTML and interpret the VBScript. The VBScript can be executed immediately,
or at a later event.
VB Scr i p t
VBScript (Visual Basic Scripting Edition) is an Active Scripting language developed
byMicrosoft that is modelled on Visual Basic. It is designed as a “lightweight” language
with a fast interpreter for use in a wide variety of Microsoft environments. VBScript uses
the Component Object Model to access elements of the environment within which it is
running; for example, the FileSystemObject (FSO) is used to create, read, update and
delete files.
A VBScript script must be executed within a host environment, of which there are
several provided with Microsoft Windows, including: Windows Script
Host (WSH), Internet Explorer (IE), and Internet Information
Services (IIS).[3] Additionally, the VBScript hosting environment is embeddable in other
programs, through technologies such as the Microsoft Script Control ([Link]).
[Link]
Basics of VB Script
VBScript Data Types
What Are 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's used.
Because Variant is the only data type in VBScript, it's also the data type returned by all
functions in VBScript.
The following table shows the subtypes of data that a Variant can contain.
Subtype Description
Empty Variant is uninitialized. Value is 0 for numeric variables or a
zero-length string ("") for string variables.
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 -922,337,203,685,477.5808 to 922,337,203,685,477.5807.
Long Contains integer in the range -2,147,483,648 to 2,147,483,647.
Single Contains a single-precision, floating-point number in the range -
3.402823E38 to -1.401298E-45 for negative values; 1.401298E-
45 to 3.402823E38 for positive values.
Double Contains a double-precision, floating-point number in the range -
1.79769313486232E308 to -4.94065645841247E-324 for
negative values; 4.94065645841247E-324 to
1.79769313486232E308 for positive values.
Date Contains a number that represents a date between January 1,
(Time) 100 to December 31, 9999.
String Contains a variable-length string that can be up to approximately
[Link]
You can use conversion functions to convert data from one subtype to another. In
addition, the VarType function returns information about how your data is stored within
a Variant.
VBScript Variables
What Is a Variable?
A variable is a convenient placeholder that refers to a computer memory location where
you can store program information that may change during the time your script is
running. For example, you might create a variable called ClickCount to store the number
of times a user clicks an object on a particular Web page. Where the variable is stored
in computer memory is unimportant. What's important is that you only have to refer to a
variable by name to see its value or to change its value. In VBScript, variables are
always of one fundamental data type, Variant.
VBScript Constants
What Is a Constant?
A constant is a meaningful name that takes the place of a number or string and never
changes. VBScript defines a number of intrinsic constants. You can get information
about these intrinsic constants from the VBScript Language Reference.
VBScript Operators
Operator Precedence
When several operations occur in an expression, each part is evaluated and resolved in
a predetermined order called operator precedence. You can use parentheses to
override the order of precedence and force some parts of an expression to be evaluated
before others. Operations within parentheses are always performed before those
outside. Within parentheses, however, standard operator precedence is maintained.
When expressions contain operators from more than one category, arithmetic operators
are evaluated first, comparison operators are evaluated next, and logical operators are
evaluated last. Comparison operators all have equal precedence; that is, they are
evaluated in the left-to-right order in which they appear. Arithmetic and logical operators
are evaluated in the following order of precedence.
[Link]
The string concatenation (&) operator is not an arithmetic operator, but in precedence it
does fall after all arithmetic operators and before all comparison operators.
The Is operator is an object reference comparison operator. It does not compare objects
or their values; it checks only to determine if two object references refer to the same
object.
• If...Then...Else statement
• Select Case statement
[Link]
VBScript Procedures
inds of Procedures
In VBScript there are two kinds of procedures; the Sub procedure and
the Function procedure.
Sub Procedures
A Sub procedure is a series of VBScript statements, enclosed by Sub and End
Sub statements, that perform actions but don't return a value. A Sub procedure can
take arguments (constants, variables, or expressions that are passed by a calling
procedure). If a Subprocedure has no arguments, its Sub statement must include an
empty set of parentheses ().
Sub ConvertTemp()
temp = InputBox("Please enter the temperature in degrees F.", 1)
MsgBox "The temperature is " & Celsius(temp) & " degrees C."
End Sub
Function Procedures
A Function procedure is a series of VBScript statements enclosed by
the Function and End Function statements. A Functionprocedure is similar to
a Sub procedure, but can also return a value. A Function procedure can take
arguments (constants, variables, or expressions that are passed to it by a calling
procedure). If a Function procedure has no arguments, its Function statement must
[Link]
In the following example, the Celsius function calculates degrees Celsius from degrees
Fahrenheit. When the function is called from the ConvertTemp Sub procedure, a
variable containing the argument value is passed to the function. The result of the
calculation is returned to the calling procedure and displayed in a message box.
Sub ConvertTemp()
temp = InputBox("Please enter the temperature in degrees F.", 1)
MsgBox "The temperature is " & Celsius(temp) & " degrees C."
End Sub
Function Celsius(fDegrees)
Celsius = (fDegrees - 32) * 5 / 9
End Function
The main reason for using a consistent set of coding conventions is to standardize the
structure and coding style of a script or set of scripts so that you and others can easily
read and understand the code. Using good coding conventions results in precise,
readable, and unambiguous source code that is consistent with other language
conventions and as intuitive as possible.
[Link]
Ar r ay Han d lin g
Arrays are a very important concept in VBScript as well as many other languages. An
array is a special type of variable which stores a set of related values.
Imagine that you would like to store a list of all the gifts you would like to receive on
your wedding day. You want to make a web page that displays a list of all the items. If
you were to create a variable for each gift then you might end up having 100 or more
variables for gifts alone! However, there is a better solution to this engineering problem.
Instead, you could utilize arrays, which allow you to store many variables(elements) into
a super variable (array). Each present would have a position in the array, starting from
position 0 and ending with the last gift
We are going to dumb down the example a little bit so that this lesson doesn't get too
boring. Let's imagine that we have 4 gifts we want to store in our array. First we need to
create an array to store our presents and tell VBScript how big we want our array to be.
VBScript Code:
<script type="text/vbscript">
Dim myArray(3)
</script>
Now that we have created our array we can begin storing information into it. The way
to do this is similar to setting the value of a variable, but because an array can hold
many values you have to specify the position at which you want the value to be saved.
We have four presents that we need to store and we make sure that we don't store
two presents in the same position!
VBScript Code:
<script type="text/vbscript">
Dim myArray(3)
myArray(0) = "Clean Underwear"
myArray(1) = "Vacuum Cleaner"
[Link]
We have all the data stored into the array that we need, now we need to figure out
how to get it back out so we can print it to the web page! This step is nearly identical to
the storing phase because you have to specify the position of the element you wish to
display. For example, if we wanted to print out the value of the present at position 0 in
our array you would use the following code:
VBScript Code:
<script type="text/vbscript">
Dim myArray(3)
myArray(0) = "Clean Underwear"
myArray(1) = "Vacuum Cleaner"
myArray(2) = "New Computer"
myArray(3) = "Talking Bass"
[Link](myArray(0))
</script>
Display:
vbscript arrays: accessing all data
The above example was a good introduction to accessing elements in an array, but it
isn't that helpful for printout out all items that might be in an array. If we had 300 items
in our array, accessing them one by one would be most time consuming to program.
Below is a piece of code that will automatically go through every element in the array
and print it out. The special programming structure this example uses is a For Loop that
we will be discussing in greater detail later on in this tutorial.
VBScript Code:
<script type="text/vbscript">
Dim myArray(3)
myArray(0) = "Clean Underwear"
myArray(1) = "Vacuum Cleaner"
myArray(2) = "New Computer"
myArray(3) = "Talking Bass"
For Each present In myArray
[Link](present)
[Link]("<br />")
[Link]
10
Next
</script>
To modify an arrays elements, refer to the array with the appropriate index number in
brackets of the value you want to change and set it to the new value.
Example:
<script type="text/vbscript"> Dim colors(4) colors(0) = "green" colors(1) = "blue"
colors(2) = "gray" colors(3) = "orange" [Link]("The old value of colors(1): " &
colors(1)) [Link]("<br />The old value of colors(3): " & colors(3)) 'change the
value of colors(1) and colors(3) colors(1) = "teal" colors(3) = "violet"
[Link]("<br />The new value of colors(1): " & colors(1)) [Link]("<br
/>The new value of colors(3): " & colors(3)) </script>
Output:
The old value of colors(1): blue The old value of colors(3): orange The new value of
colors(1): teal The new value of colors(3): violet
[Link]
11
Use r I n t e r a ct i o n i n VB Scr i p t
The language of VBScript is modelled on Visual Basic, and therefore can be reviewed
using similar categories: procedures, control structures, constants,
variables, user interaction, array handling, date/time functions, error handling,
mathematical functions, objects, regular expressions, string manipulation, and so on.[14]
The following are some key points of introduction to the VBScript language.
A “procedure” is the main construct in VBScript for separating code into smaller
modules. VBScript distinguishes between a function, which can return a result in an
assignment statement, and a subroutine, which cannot. Parameters are positional, and
can be passed by value or by reference.
Control structures include the usual iterative and conditional Do Loops, If-Then-Else
statements, and Case statements, with some more complex variants, such as ElseIf
and nested control structures.
As a memory aid in coding, and certainly for readability, there are a large number of
constants, such as True and False for logical values, vbOKCancel and vbYesNo for
MsgBox codes, vbBlack and vbYellow for color values, vbCR for the carriage return
character, and many others.
Variables by default have “Variant” type, but it is possible (and sometimes necessary) to
force a particular type (integer, date, etc.) using conversion functions (Cint, CDate, etc.)
User interaction is provided through the functions MsgBox and InputBox which provide
a simple dialogue box format for messages and input. Both functions display prompting
messages, with the former returning a standard response, and the latter returning
one user-supplied text or numeric value. For more elaborate GUI interaction with
controls, VBScript can be used in combination with HTML, for example, in anHTML
Application. Event-driven forms are not supported as in Visual Basic or Visual Basic for
Applications.
Names are not case-sensitive; therefore, for example, MsgBox and msgbox, or
FileSystemObject and filesystemobject, are treated as the same name. However, as
usual, it is considered a best practice of VBScript style to be consistent and to
capitalize judiciously.
[Link]
12
H a n d l i n g Ru n t i m e Er r o r s
Welcome to Sesame Script, the column for beginning script writers. The goal of this
column is to teach the very basics of Windows scripting for system administration
automation. We’ll provide you with the information you’ll need to begin reading and
understanding scripts and to start modifying those scripts to suit your own needs. If
there’s anything in particular about scripting you’re finding confusing, let us know;
you’re probably not alone.
What’s the Problem?
Troubleshooting vs. Error Handling
Error Types
Don’t Stop Now
Not Complete Denial
Be Explicit
That’s It?
W h a t ’ s t h e Pr o b l e m ?
Have you ever worked on a team where one person always seems to be causing
problems? If anything ever goes wrong, it can typically be linked to that person in some
way. Sometimes it might not even be this person’s fault (not entirely, anyway), but this
particular person just always turns out to be the scapegoat. Believe it or not, the
Scripting Guys have someone like that, too (but Dean doesn’t like to talk about it, so we
won’t mention that it’s him). Things happen, mistakes are made, and there’s always one
person to point a finger at.
The problem with writing scripts is that it’s hard to blame anyone else when your script
doesn’t work the way you want it to. (Well, you could blame Dean; he may very well
have had something to do with it.) But, most of the time, you wrote the script, or
modified someone else’s script, and now it just doesn’t work. What do you do now? You
could spend several days contemplating the unfairness of the world and cursing the day
you ever heard of scripting, or you could simply do some troubleshooting.
Tr o u b l e sh o o t i n g v s. Er r o r H a n d l i n g
We’re going to talk about troubleshooting and error handling, so we should probably
start by explaining what the difference is between the two. Simply put, troubleshooting is
figuring out what went wrong; error handling is knowing what could go wrong and
dealing with it ahead of time. We’re not really going to distinguish between the two in
this discussion, we’re just going to get you started with a couple of simple techniques
you can use to get out of trouble and stay out.
Er r o r Ty p e s
There are three types of errors: syntax, runtime, and logic.
Sy n t a x Er r o r s
Syntax errors are usually the result of an incorrectly used keyword. Here are a couple of
examples:
[Link]
13
intNumber = 2
If intNumber = 2 Then
[Link] intNumber
Edn If
intNumber = 2
If intNumber = 2
[Link] intNumber
End If
In the first example, take a look at the closing End If statement. End is spelled Edn.
VBScript doesn’t know what Edn means, so it thinks the If statement doesn’t have an
End If and returns an error. In the second example we left the Then keyword off of the If
Then statement. Again, VBScript is expecting a Then but doesn’t see one, so it will
return an error.
VBScript catches syntax errors before it tries to run the script and displays an error
message if any of these errors are found. When you type cscript [Link] at the
command prompt, VBScript will look at the script and determine whether all the If’s have
matching Then’s and that all other syntax issues are okay. Only if they are will it try to
run the script.
Tip: Because syntax errors are checked before a script runs, a safe way to
check for syntax errors is to [Link] as the first line in your script,
like this:
[Link]
intNumber = 2
If intNumber = 2
[Link] intNumber
End If
You might have a script that is designed to delete files or change properties
in Active Directory. Maybe you’re still working on your script but you want to
check and make sure your syntax is correct before you actually delete or
change anything. Adding [Link] to the beginning of your script is an
easy way to do this. When you try to run the script, it will be checked for
syntax errors. If errors are found, they’ll be output to the screen and the script
will never run. If there aren’t any syntax errors the script will run, but the very
first line ends the script and no other lines are executed. You’ve just safely
[Link]
14
tested the syntax of your script without actually running any of the script code.
Ru n t i m e Er r o r s
Once you get through the syntax checks with no errors VBScript tries to run the script.
At this point you might still get an error, but this time it’s a runtime error, meaning the
error occurs when the script is running. An example of a runtime error would be trying to
connect to a computer that doesn’t exist. VBScript has no way of knowing this ahead of
time; the script needs to run and actually attempt to connect to the computer before it
finds out there is no computer by that name (or it’s offline, or whatever). At that point
you’ll receive an error message letting you know something went wrong.
Lo g i c Er r o r s
Logic errors are usually the most difficult errors to find. With a logic error, VBScript
decides the script looks okay, the script runs and completes with no problems, but you
don’t get the results you expect. Here’s an example of how that could happen:
intNumber = 2
If intNumber > 0 Then
[Link] "Greater than zero"
ElseIf intNumber > 1 Then
[Link] "Greater than one"
ElseIf intNumber > 2 Then
[Link] "Greater than two"
End If
In this example, we’ve set intNumber equal to 2. When you go into the If statement, you
might expect to receive the message “Greater than one.” And when you look at the
choices that might make sense: we check to see if intNumber is greater than 0, which it
is. Then we check to see if it’s greater than 1, and yes, 2 is greater than 1. Finally we
check to see if it’s greater than 2, which it’s not. So our message should be “Greater
than one,” right? Nope. The way an If-ElseIf statement works is that the first If statement
will be checked: is intNumber greater than 0? If it is, the message “Greater than zero”
will be echoed to the screen, and you’ll go straight to the End If statement. The ElseIf
statements will never happen.
As you can see, there’s nothing actually wrong with this script, it does exactly what it’s
supposed to; it just doesn’t do exactly what you want it to. You have an error in the logic
of your script, or the way the script works.
D o n ’ t St o p N o w
Have you ever noticed how good people can be at denial? “I’m not going bald, I just
have a high forehead.” “No, that wasn’t my child kicking the back of your seat and
[Link]
15
talking all through the movie.” “There are no errors in my script, there’s something
wrong with the computer.”
N o t Co m p l e t e D e n i a l
You might not want to completely ignore errors. In the preceding script, you might not
want the script to come to a crashing halt when it gets to an invalid date, but you also
might not want to just skip right by it. Maybe you want to know that there is invalid
information in your data set. But if you put On Error Resume Next in your script and
ignore errors, how do you know they happened? Simple: just ask.
VBScript provides an object called the Err object. When an error occurs in a VBScript
method that method returns an error number that you can access through the Number
property of the Err object. So if the Number property is anything except zero, an error
has occurred.
Be Ex p l i ci t
This is an area we discussed in a previous article, but we can’t discuss error handling
without mentioning it: theOption Explicit statement. Let’s go back to our earlier
example:
intNumber = 2
If intNumber = 2 Then
[Link] intNubmer
End If
When you run this script you’re probably expecting it to echo back 2. What it will do
instead is echo nothing. If you look closely, you can see that in the [Link]
statement, our variable is spelled incorrectly, inNubmer rather than intNumber. This
doesn’t produce an error. VBScript simply thinks you’re using a different variable, which
you never actually gave a value so it defaulted to nothing. This type of error can be
difficult to spot (even removing an On Error Resume Next statement won’t help you)
because there’s no error for VBScript to report. One way to guard against this type of
error is to include the Option Explicit statement:
Option Explicit
intNumber = 2
If intNumber = 2 Then
[Link] intNubmer
End If
Now when you run the script you’ll receive an error message:
[Link]
16
Dim intNumber
intNumber = 2
If intNumber = 2 Then
[Link] intNubmer
End If
Now when you run your script you get an error message that will actually help you:
Th a t ’ s I t ?
There is much more to error handling than the little bit we’ve shown you here in this
article. But we’re tired of working now, so this is all you get.
(Oops, our manager just walked by and saw that.) No, really, just kidding, we never get
tired of working. And we’dnever leave our devoted readers without making sure we’d
provided as much information as we possibly could. But what we have done here is give
you a quick overview of error-handling, and shown you just a few types of errors you
might encounter. For more in-depth information and some intermediate-to-advanced
error-handling techniques, take a look atTo Err is VBScript. And of course, there’s
always the handy Windows 2000 Scripting Guide, loaded with information.
[Link]
17
PROGRAMES OF UNIT - II
Program Output
<html>
<body>
This is my first VBScript!
<script type=”text/vbscript”>
[Link]("This is my first VBScript!")
</script>
</body>
</html>
<html>
<body>
Hello World!
<script type=”text/vbscript”>
[Link]("Hello World!")
</script>
</body>
</html>
VBScript Array
<html> 20
<body>
<script type=”text/vbscript”>
a=Array(5,10,15,20)
[Link](a(3))
</script>
</body>
</html>
<html>
<body>
5
<script type=”text/vbscript”>
a=Array(5,10,15,20)
[Link](a(0))
</script>
</body>
</html>
<html>
<body>
5
<script type=”text/vbscript”>
10
a=Array(5,10,15,20)
15
for each x in a
20
[Link](x&”<br/>
next
</script>
</body>
</html>
KNOWLEDGE IS POWER
[Link]
I N D EX – UN I T - V
S.n o : Ti t l e Pa g e n o :
Ex t e n si b l e M a r k u p La n g u a g e ( XM L) –
1. 02 - 04
I n t r o d u ct i o n
2. Cr e a t i n g XM L D o cu m e n t s 05 - 05
3. XM L St y l e Sh e e t s 06 - 07
Co m p a r i so n o f XM L w i t h o t h e r W e b
4. 08 - 09
D e si g n i n g La n g u a g e s
5. XM L D o cu m e n t Ob j e ct M o d e l 10 - 11
6. XM L Qu e r y La n g u a g e 12 - 14
7. XM L D TD 15 - 17
[Link]
Co m p a r i so n o f XM L w i t h o t h e r W e b D e si g n i n g La n g u a g e s
Co m p a r i n g XM L w i t h H TM L
1. XML is designed to carry the data while html is to display the data and focus on how the
data looks.
2. XML does not do anything but it is used to structure the data, store the data and
transport the data while HTML is used to display the data only.
3. XML is cross platform, hardware and software independent tool to carry data from one
source to another destination.
4. XML is self descriptive. The DTD or schema describes what and how to use tags and
elements in an xml document.
5. XML does not have predefined tags while HTML has. XML lets you invent your own tags
while html gives you predefined tags and you have to use them only.
6. XML is extensible as you can add your own tags to extend the xml data.
7. XML is a complement to HTML not the replacement. Most likely use of xml is to transfer
the data between incompatible systems as xml is cross platform. XML has now
established a strong foundation in the world of web development.
8. XML can separate the data from html. While working on html, instead of storing data in
html you can store the data in a separate xml file to make the html code cleaner and
easier. Now you can concentrate on working in html rather than storing data. It also
eliminates the need to change in html when xml data is changed.
9. XML tags are case sensitive while html tags are not.
10. Attribute values must always be quoted in xml while its not the case with html.
11. XML elements must be properly nested while html is not so sensitive.
[Link]
XM L H TM L CSS
A set of rules for encoding The predominant markup A style sheet
documents in machine- languagefor web pages. HTML is language used to describe
readable form. The design the basic building-blocks of the presentation
goals of XML emphasize webpages. The purpose of a web semantics (the look and
simplicity, generality, and browser is to read HTML formatting) of a document
usability over the Internet.[6] It documents and compose them written in a markup
is a textual data format with into visual or audible web pages. language. Its most
strong support via Unicode for The browser does not display the common application is to
the languages of the world. HTML tags, but uses the tags to style web pages written
Although the design of XML interpret the content of the page. in HTML and XHTML, but
focuses on documents, it is HTML elements form the building the language can also be
widely used for the blocks of all websites. HTML applied to any kind
representation of arbitrarydata allows images and objects to be of XML document,
structures, for example in web embedded and can be used to including plain
services. create interactive forms. It XML, SVG and XUL.
provides a means to
create structured documents by
denoting structural semantics for
text such as headings,
paragraphs, lists, links, quotes
and other items.
[Link]
15
XM L D o cu m e n t Ty p e D e f i n i t i o n ( D TD ) :
The oldest schema language for XML is the Document Type Definition (DTD), inherited
from SGML.
DTD support is ubiquitous due to its inclusion in the XML 1.0 standard.
DTDs are terse compared to element-based schema languages and consequently
present more information in a single screen.
DTDs allow the declaration of standard public entity sets for publishing characters.
DTDs define a document type rather than the types used by a namespace, thus
grouping all constraints for a document in a single collection.
DTDs have the following limitations:
The purpose of a DTD is to define the legal building blocks of an XML document. It
defines the document structure with a list of legal elements. A DTD can be declared
inline in your XML document, or as an external reference.
[Link]
16
W h y u se a D TD ?
XML provides an application independent way of sharing data. With a DTD, independent groups of people can agree
to use a common DTD for interchanging data. Your application can use a standard DTD to verify that data that you
receive from the outside world is valid. You can also use a DTD to verify your own data.
Va l i d XM L D o cu m e n t s
A " Valid" XML docum ent is a " Well Form ed" XML docum ent , which also conform s t o t he rules of a
Docum ent Type Definit ion ( DTD) :
The DOCTYPE declarat ion in t he exam ple above, is a reference t o an ext ernal DTD file. The cont ent of
t he file is shown in t he paragraph below.
XM L D TD
The purpose of a DTD is t o define t he st ruct ure of an XML docum ent . I t defines t he st ruct ure wit h a
list of legal elem ent s:
<!DOCTYPE note
[
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
I f you want t o st udy DTD, you will find our DTD t ut orial on our hom epage.
The purpose of a DTD ( Docum ent Type Definit ion) is t o define t he legal building
blocks of an XML docum ent .
A DTD defines t he docum ent st ruct ure wit h a list of legal elem ent s and
at t ribut es.
[Link]
17
]>
[Link]