You are on page 1of 9

Java Script

Scripting Language

Introduction
A compact, object-based scripting language for developing client and server Internet applications Two Types :
1. Navigator JavaScript, also called client-side JavaScript embedded in an HTML page LiveWire JavaScript, also called server-side JavaScript enables you to create server-based applications similar to Common Gateway Interface (CGI) programs

2.

JavaScript in Navigator
Netscape Navigator 2.0 (and later versions)
interpret JavaScript statements embedded in an HTML page

When Navigator requests such a page, the server sends the full content of the document, including HTML and JavaScript statements, over the network to the client The Navigator then displays the HTML and executes the JavaScript, producing the results that the user sees

Client-side JavaScript
Can respond to user events such as mouseclicks, form input, and page navigation For example:
You can write a JavaScript function to verify that users enter valid information into a form requesting a telephone number or zip code Without any network transmission, the HTML page with embedded JavaScript can check the entered data and alert the user with a dialog box if the input is invalid

JavaScript, the language


JavaScript has the following elements: Keywords, statement syntax and grammar Rules for expressions, variables and literals Underlying object model Built-in objects and functions Different versions of JavaScript work with specific versions of Navigator

JavaScript
1. Interpreted (not compiled) by client 2. Object-based. Uses built-in, extensible objects, but no classes or inheritance 3. Code integrated with, and embedded in, HTML 4. Variable data types not declared (loose typing)

And

Java

1. Compiled bytecodes downloaded from server, executed on client 2. Object-oriented. Applets consist of object classes with inheritance 3. Applets distinct from HTML (accessed from HTML pages)

4. Variable data types must be 5. Dynamic binding. Object declared (strong typing) references checked at runtime
6. Cannot automatically write to hard disk

5. Static binding. Object references must exist at compile-time 6. Can write to hard disk

Embedding JavaScript in HTML


As statements and functions within a <SCRIPT> tag By specifying a file as the JavaScript source (rather than embedding the JavaScript in the HTML) By specifying a JavaScript expression as the value for an HTML attribute As event handlers within certain other HTML tags (mostly form elements)

Using the SCRIPT tag


The <SCRIPT> tag is an extension to HTML that can enclose any number of JavaScript statements as shown here:
<SCRIPT> JavaScript statements... </SCRIPT>

A document can have multiple SCRIPT tags, and each can enclose any number of JavaScript statements

Working Example: index.html


<html> <head> <title>JavaScript_Examples</tit le> </head> <body> <P> <SCRIPT LANGUAGE="JavaScript"> <!--- Hide script from old browsers.document.write("H ello, net!") // End the hiding here. --> </SCRIPT> </body> </html>

Hello, net!

You might also like