[go: up one dir, main page]

0% found this document useful (0 votes)
34 views5 pages

SECTION 3

Uploaded by

AYUSH MANAV
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views5 pages

SECTION 3

Uploaded by

AYUSH MANAV
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

JavaScript

SECTION 3 JAVASCRIPT
Structure
3.0 Script Basics
3.1 Incorporating JavaScript into a Web Page
3.2 Exercises for Practice in Lab Sessions.

3.0 JAVASCRIPT BASICS


The World Wide Web (WWW) began as a text-only medium. The first version does
not even have the capability to include graphics on a page.

Today’s Web sites include graphics, sound animation, video and sometimes even
useful content! Web scripting languages, such as JavaScript, are one of the easiest
ways to spice up the Web page and to interact with users in new ways, HTML, unlike
which is a simple text markup language, which can’t respond to the user, make
decisions, or automate repetitive tasks. Web scripting languages allow you to
combine scripting with HTML to create interactive Web pages.

A script in JavaScript can range from a single line to a full-scale application.


JavaScript was developed by Netscape Communications Corporation, the makers of
the popular Netscape Navigator Web browser. JavaScript was the first Web scripting
language to be introduced, and it is by far the most popular. Here are a few things you
can do with JavaScript:

• Add scrolling or changing messages to the browser’s status line.


• Validate the contents of a form and make calculations.
• Display messages to the user, either as part of a Web page or in alert boxes.
• Animate images or create images that change when you move the mouse over
them.
• Detect the browser in use and display different content for different browsers.
• Detect installed plug-ins and notify the user if a plug-in is required.

3.1 INCORPORATING JAVASCRIPT INTO A WEB


PAGE
As you, hopefully, already know, HTML (Hypertext Markup Language) is the
language you use to create Web documents. You must have created “Hello World!”
as given below:
<HTML>
<HEAD><TITLE>My First Page</TITLE></HEAD>
<BODY>
Hello World!
</BODY>
</HTML>

To add JavaScript to a page, you’ll use a similar tag: <SCRIPT>.

The <SCRIPT> tag tells the browser to start treating the text as a script, and the
</SCRIPT> tag returns to the regularly scheduled HTML as given below. Note that
the file will be stored as .html or .htm.

13
Lab Manual

The output of the above program will be

In this example, we placed the script within the body of the HTML document. There
are actually 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.

14
• Within an HTML tag. This is called an event handler and allows the script to JavaScript
work with HTML elements. Event handlers are one type of script where you
don’t need to use the <SCRIPT> tag.
• In a separate file entirely JavaScript supports the use of files with the .js
extension containing scripts; these can be included by specifying a file in the
<SCRIPT> tag. This feature works only in Netscape Navigator 3.0 or later and
Internet Explorer 4.0 or later.

3.2 EXERCISES FOR PRACTICE IN LAB SESSION


SESSION 1
Exercises
1. How would you write any statement using only one write() or writeln()
command?

2. Embed JavaScript in HTML document asking user’s name and then printing
Hello <User_Name>

3. Create a dialogue box with “Welcome to my Website” message.

SESSION 2
Exercises
1. Evaluate the expression:
a. 7+5
b. “7” + “5”
c. 7*5
d. 7/5
e. 7%5

2. Write the segment of Script that would ask the user if he wants a greeting
message and if he does, display a Gif file called Welcome .gif and display
“Welcome to Netscape Navigator!” in the document window following the Gif

3. Write the object definition for an object called car with four properties model,
make, year & price.

SESSION 3
Exercises
1. Write a program to display a multiplication table.

2. Write a code to create a scrolling text in a text box.

3. Write a JavaScript code to create a pull down menu box.

SESSION 4
Exercises
1. Write a program to move a text with mouse pointer.

2. Write a program to change colour of text randomly.

15
Lab Manual 3. Create a Web page using two image files, which switch b/w one another as the
mouse pointer moves over the image. Use the On Mouse over and On Mouse
out event handler

SESSION 5
Exercises
1. Write a JavaScript code to accept radius & display the area of the circle.

2. Use the date function get Date & set Date to prompt the user for an integer b/w
1 – 31 & return day of the week it represents.

3. Display time and print message accordingly e.g., ‘Good Morning’ in Morning
etc.

SESSION 6
Exercises
1. Using JavaScript create a digital clock.

SESSION 7
Exercises
1. Using JavaScript create a calculator.

SESSION 8
Exercises
1. Create an HTML form that has a number of text boxes. The user fills the
textboxes with data. Write a script that verifies that all textboxes have been
filled. If a text box has been left empty pop up an alert message indicating the
box that has been left empty. When OK button is clicked, set focus to that
specific textbox. If all the textboxes are filled, display thank you.

SESSION 9
Exercises
1. Create an HTML form that inputs employee details and display the same on the
HTML page.

2. Write a program, which prompts the user to enter a sum of two numbers and
display whether the answer is correct or incorrect.

SESSION 10
Exercises
1. Illustrate how the reset button on form functions.

2. Create a program to check for null or empty string.

SESSION 11
Exercises
1. Create a program to generate a hit counter.
16
2. Create a program to verify whether email address provided by the user is valid JavaScript
or invalid.

SESSION 12
Exercises
1. Write a program to scroll the text on status bar.

2. Write a program to create a small window in main window.

SESSION 13
Exercises
1. The form consists of two multiple choice lists and one single choice list

a. The first multiple choice list displays the major dishes available.
b. The second multiple choice list displays the stocks available.
c. The single choice list displays the miscellaneous (Milkshakes, soft drinks,
softy etc. available)

SESSION 14
Exercises
1. Create a Web page with two forms, one office copy and one customer copy
when user enters date in customer copy it gets updated in office copy.

SESSION 15
Exercises
1. Use JavaScript for authentication and verification of the textboxes in the static
site developed by the student in the HTML exercise.

17

You might also like