CMPS 335 Advanced Web Publishing
JavaScript Programming
Introduction to JavaScript
HTML is a text markup language. Web pages generated by HTML code
are static, and they can not respond to the user, make decisions, perform
computations, or do iterative operations. These dynamic and
interactive tasks require the use of a programming language such as
Perl or a scripting language such as JavaScript. The term scripting
language usually refers to programming languages that are executed by an
interpreter from within a Web browser. Scripting languages are
generally less complex and are easier to learn. Programming and
scripting languages make Web documents dynamic and interactive.
They extend the capabilities of HTML and greatly enhance the
functionality and appearance of Web pages. JavaScript is a
scripting language designed for programming interactive Web
sites. Virtually all Web browsers support JavaScript.
Some of Useful JavaScript Applications
- Create status-line messages.
- Validate contents of a form.
- Display messages to the user in alert boxes.
- Create images that change when the mouse moves over them.
- Create and open new windows.
- Create animation.
JavaScript and Java
JavaScript borrows much of its syntax from the Java language.
However, JavaScript and Java are different languages. JavaScript is an
interpreted language the JavaScript code is embedded in HTML documents.
Java is a compiled language developed by Sun Microsystems.
Java can be used to create applets that are compiled by a Java compiler
into Java class files and used in the Web documents. The
applet code is not embedded in the HTML document. The following is
a summary of some important differences between JavaScript and Java.
JavaScript Java
------------------------------------------------------------------
Object-based Object-oriented
Source code embedded in HTML Source code not in HTML document
Interpreted by the browser Compiled applet downloaded
and executed by the client
* The term object-based refers to a programming language that uses
the concepts of objects, methods, and events but does not provide
all of the complexity of a true object-oriented language.
Java is a powerful general-purpose programming language and can be
used for complex applications. JavaScript works only in Web
browsers and is best suited to simpler applications. JavaScript is
faster than Java for simple tasks because there is usually a delay of 10
seconds or longer to start a Java applet.
The JavaScript Language
JavaScript is the first scripting language developed by Netscape
for programming interactive Web sites. The Microsoft's version of
JavaScript is called JScript. ECMAScript is the standardized
version created by the ECMA (European Computer Manufacturer's
Association). JavaScript 1.3 follows the ECMA-262 standard.
JavaScript (client-side JavaScript) is a popular language supported by
most browsers.
JavaScript is an object-based programming language. JavaScript
scripts are embedded in HTML code and they are executed by an interpreter
from within a Web browser. The interpreter is a component of the
browser that translates the JavaScripte code into an executable format each
time the script is run. JavaScript is now available in two formats:
client-side JavaScript and server-side JavaScript. You can use
a JavaSxript (client-side) script to program and control elements of
Web pages without depending on CGI scripts on a server. The
client-side JavaScript is not always sufficient when building truly
interactive Web-based applications. For example, a JavaScript
script can not access a database or an external data file.
- Client-side JavaScript
This is the format available to HTML pages. You can include
JavaScript code directly in the HTML document, and the script is
interpreted and displayed by Web browsers.
- Server-side JavaScript
This is the format used with Web server to access file systems,
communicate with other applications, and perform other tasks.
Currently, server-side JavaScript is proprietary and
vendor-specific.
Return to Web Site Home Page