Unit 3 (F)
Unit 3 (F)
lncte/cse/cs504(A)
Outline
•Introduction to javascript
•Objective of Javascript
•Core syntax and structure of Javascript
•Popular function
lncte/cse/cs504(A)
History of JavaScript
JavaScript was initially developed by Brendan Eich as
part of the Netscape release 2.0.
At that time it is named as LiveScript then name
change to JavaScript just to gain the hype since Java
language is very popular.
There are strong similarities between the core syntaxes
of JavaScript and Java, C++.
lncte/cse/cs504(A)
History of JavaScript
JavaScript became popular because of the rollover
effect used by most of the web developers that time.
In competition Microsoft come with its own Scripting
language known as JScript in 1996.
Then Netscape and Sun Microsystems went
approached an Organization known as
ECMA(European Computer manufacturers association
to produce a standard for JavaScript and as result of it
the ECMA-262 standard was released in the year 1999.
ECMAScript 6 (released in June 2015) is the latest
official version of JavaScript
lncte/cse/cs504(A)
What is JavaScript?
The growth of the WWW has resulted in a demand for
dynamic and interactive web sites.
Browsers have limited functionality
Text, images, tables, frames
JavaScript introduces a quotient of interactivity
Browser/page manipulation
Reacting to user actions
A type of scripting language which is
Easy to learn
Developed by Netscape
Now a standard
www.ecma-international.org/publications/
standards/ECMA-262.HTM
lncte/cse/cs504(A)
JavaScript Allows Interactivity
Improve appearance
Especially graphics
Visual feedback
Site navigation
Perform calculations
Validation of input
Other technologies
javascript.internet.com
lncte/cse/cs504(A)
How Does It Work?
JavaScript is Embedded within a HTML page
View source
Executes on client
Fast, no connection needed once loaded
Simple programming statements combined with
HTML tags
Interpreted by web browser
No special tools required
lncte/cse/cs504(A)
Uses of JavaScript
JavaScript can be used effectively for interaction with the
end user as it supports form elements such buttons,
textboxs, menus etc.
Easily create pop-up alert, windows etc.
JavaScript also support Event driven Programming.
Whenever a user clicks the mouse or hits the keys on the
keyboard or even submit the form then these events and
responses to them can be handled by JavaScript.
JavaScript mainly used in web development for Form
validation and input validation etc. This validity checking
is done at the client side only. The server does not have to
waste time in validity checking and hence improve Client
server communication.
lncte/cse/cs504(A)
JavaScript Versions
JavaScript 1.0
Supported by Netscape 2.0 and IE 3.0
JavaScript 1.1
Supported by Netscape 3.0 and IE 4.0
JavaScript 1.2
Supported by Netscape 4.0 and IE 4.0
JavaScript 1.3
Supported by Netscape 4.5 and IE 5.0
JavaScript 1.5
Supported by Netscape 6.0 and IE 5.5 and later
lncte/cse/cs504(A)
The Future of JavaScript
ECMA standard brings JavaScript and Jscript
together.
ECMA - An International industry association dedicated
to standardize information and communication systems.
Both Netscape and Microsoft have pledged that
they will support and develop JavaScript in the
future.
It is future-proof, and it is not going to disappear
in the near future.
lncte/cse/cs504(A)
JavaScript three parts
Core: It includes operators, expressions, statements
and subprograms.
Client-side: It is a collection of objects using which one
can have control over the browser and user-browser
interaction is possible.
Server-side: It is a collection of objects using which
one can access the database on the server.
lncte/cse/cs504(A)
Difference between JavaScript and
Java JavaScript Java
JavaScript is a scripting language Java is a Programming language
lncte/cse/cs504(A)
A Simple Script
<html>
<head> <title>First JavaScript Page</title> </head>
<body>
<h1>First JavaScript Page</h1>
<script type="text/javascript">
<!--
document.write("<hr>");
document.write("Hello World Wide Web");
document.write("<hr>");
-->
</script>
</body>
</html>
lncte/cse/cs504(A)
Embedding JavaScript
<html>
<head>
<title>First JavaScript Program</title>
</head>
<body>
<script language=“JavaScript” src=“your_source_file.js”></script>
</body>
</html>
lncte/cse/cs504(A)
JavaScript Source File
<script language=“JavaScript”
src=“your_source_file.js”></script>
lncte/cse/cs504(A)
Need for a source file
If the JavaScript code is fairly short, you are
recommended to include the code in the HTML
document.
To add clarity to an HTML document.
To share JavaScript code across multiple HTML
documents.
To help you hide your JavaScript code.
Spent lot of time for JavaScript coding.
Viewer can only see the location of the source file but
not the contents.
lncte/cse/cs504(A)
Using the alert() Method
<head>
<script language=“JavaScript”>
alert(“An alert triggered by JavaScript”);
</script>
</head>
WT kirtiraj 18
Using the prompt() Method
<head>
<script language=“JavaScript”>
prompt(“What is your student id number?”);
prompt(“What is your name?”,”No name”);
</script>
</head>
WT kirtiraj 20
Function of JavaScript with Display
Possibilities