Section 4
Section 4
SECTION 4 VBSCRIPT
Structure
4.0 VBScript Basics
4.1 Incorporating VBScript into HTML Page
4.2 Exercises for Practice in Lab Sessions
The Web browser receives scripts along with the rest of the Web document. The
browser parses and processes the scripts. HTML was extended to include a tag that is
used to incorporate scripts into HTML-the <SCRIPT> tag.
The LANGUAGE attribute of SCRIPT tag specifies the language used for scripting.
Scripts are usually placed at the top of the Web document, in the HEAD. There are
four different places where you can use scripts:
• In the body of the page. In this case, the output of the script is displayed, as part
of the HTML document, when the browser loads the page.
• In the header of the page, between the <HEAD> tags. Scripts in the header
aren’t executed immediately, but can be referred to by other scripts. The header
is often used for functions-groups of VBScript statements that can be used as a
group.
• Within an HTML tag. This is called an event handler and allows the script to
work with HTML elements. Event handlers are the one type of script where you
don’t need to use the <SCRIPT> tag.
• In a separate file entirely.
Not all browsers support scripting languages. To handle such browsers you can
enclose your script in comment tags (<!-- and -->).
2. Create a Web page that displays a message box with the message:
“Welcome to my Website”
SESSION 2
Exercises
1. Write a VBScript code that accepts the length, breadth and height and displays
the area of a rectangle.
SESSION 3
Exercises
1. Write a programme, which prompts, the user to enter the sum of two numbers
and display whether the answer is correct or incorrect.
SESSION 4
Exercises
1. Create a programme to check for null or empty string.
2. Create a form that has an e-mail field. Now write VBScript code for validation
of the email address.
SESSION 5
Exercises
1. List the Mouse and Keyboard events in VBScript.
SESSION 6
Exercises
1. Create a form in HTML containing the following fields and then perform the
validation of each field using VBScript.
Name - textbox
Address - textbox
Date of Birth - a combo box (one for each, day, month and
year)
Email - textbox
2. How do you declare variables in VBScript and enlist the various variables-
naming rules.
19
Lab Manual SESSION 7
Exercises
1. What is the purpose of Option Explicit in VBScript code?
2. Using an HTML form accept the Principal, Rate of Interest and Time from the
user, validate the three fields and then display the Simple Interest to the user.
SESSION 8
Exercises
1. Create a programme that accepts the time from the system clock and
accordingly displays a Good Morning, Good Afternoon or Good Evening
message to the user. Use If – Then – Else statement.
SESSION 9
Exercises
1. Write a programme in VBScript that uses For..Next looping statement to create
a Fibonacci series.
SESSION 10
Exercises
1. Write a programme that displays the multiplication of two matrices.
3. Write a programme that accepts a number from the user and displays its
factorial only if it is a prime number.
20