0% found this document useful (0 votes)
95 views4 pages

Practical 6

The document discusses using JavaScript to add interactivity to web pages. It provides the standard procedure for creating and viewing a JavaScript program using a text editor and web browser. It describes what JavaScript is, its start and end tags, and that it is case sensitive. Examples are given of JavaScript statements, variables, code, and different types of event handlers like alert, confirm, and prompt boxes.

Uploaded by

Sunil Dhankhar
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)
95 views4 pages

Practical 6

The document discusses using JavaScript to add interactivity to web pages. It provides the standard procedure for creating and viewing a JavaScript program using a text editor and web browser. It describes what JavaScript is, its start and end tags, and that it is case sensitive. Examples are given of JavaScript statements, variables, code, and different types of event handlers like alert, confirm, and prompt boxes.

Uploaded by

Sunil Dhankhar
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/ 4

Web Designing and Internet Applications 1

Aim: - Write program to understand the basic concepts of JavaScript and its dialog boxes.

Tools: Notepad Editor and Web Browser like Internet Explorer, Google Chrome or Mozilla
Firefox.

 Standard Procedure for Creating and View a JavaScript program:


1. Use a text editor such as Notepad/Notepad++ to write the document.
2. Save the file as filename.html on a PC. This is called document Source.
3. Double click on the file to run the program.
4. Your HTML page should now appear just like any other Web page in browser.
5. You may now switch back and forth between the Source and the HTML page.
 switch to Notepad with the Document Source
 make changes .
 save the document again.
 switch back to browser .
 click on RELOAD and view the new HTML page.
 switch to Notepad with the Document Source.

Theory:

What is JavaScript?

• JavaScript was designed to add interactivity to HTML pages


• JavaScript is a scripting language
• A scripting language is a lightweight programming language
• JavaScript is usually embedded directly into HTML pages
• JavaScript is an interpreted language (means that scripts execute without preliminary
compilation)
• Everyone can use JavaScript without purchasing a license

Start End Tag:


<script type="text/javascript">
</script>

JavaScript is Case Sensitive

Unlike HTML, JavaScript is case sensitive - therefore watch your capitalization closely when
you write JavaScript statements, create or call variables, objects and functions.
Web Designing and Internet Applications 2

JavaScript Statements

A JavaScript statement is a command to a browser. The purpose of the command is to tell the
browser what to do. This JavaScript statement tells the browser to write "Hello” to the web
page:

document.write("Hello ");

It is normal to add a semicolon at the end of each executable statement. Most people think this
is a good programming practice, and most often you will see this in JavaScript examples on
the web.
The semicolon is optional (according to the JavaScript standard), and the browser is supposed
to interpret the end of the line as the end of the statement. Because of this you will often see
examples without the semicolon at the end.
JavaScript Code

JavaScript code (or just JavaScript) is a sequence of JavaScript statements. Each statement is
executed by the browser in the sequence they are written.

Example:

<html>
<body>
<script type="text/javascript"> document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph.</p>"); document.write("<p>This is another
paragraph.</p>");
</script>
</body>
</html>

JavaScript Variables Example:


<html>
<body>

<script type="text/javascript"> var firstname; firstname="Hege"; document.write(firstname);


document.write("<br />"); firstname="Tove"; document.write(firstname);
</script>
<p>The script above declares a variable, assigns a value to it, displays the value, changes the value,
and displays the value again.</p>
</body>
</html>
Web Designing and Internet Applications 3

Event Handler

1. Alert:

<html>
<head>
<form>
<input type="button" onclick="alert('Are you sure you want to give us the deed to your house?')"
value="Confirmation Alert">
</form>
</head>
</html>

2. Confirm

<head>
<script type="text/javascript">
<!--
function confirmation() {
var answer = confirm("really want to leave this website?");
if (answer){
alert("Bye bye user!");
window.open("http://www.google.com/");
}
else{
alert("Thanks for sticking around!");
}
}

</script>
</head>
<body>
<form>
<input type="button" onClick="confirmation()" value="Leave this site?">
</form>
<p >Click on the button to check the confirm dialog box!</p>
</body>
Web Designing and Internet Applications 4

3. Prompt

<html>
<head>
<script>
function myFunctionPro() {
var person = prompt("Please enter your name", "enter name");
if (person == null || person == "") {
txt = "User cancelled the prompt.";
alert(txt);
} else {
txt = "Hello " + person + "! How are you today?";
alert(txt);
}
}
document.write(Date());
</script>
</head>
<body>
<p>Click the button to display an Prompt box.</p>
<button onclick="myFunctionPro()">Try Prompt</button>
</body>
</html>

Conclusion:

The JavaScript code is successfully executed and provided the information to use the syntax,
tag and dialog boxes to the users.

You might also like