Cnit 133 Interactive Web Pags - Javascript and Ajax
Cnit 133 Interactive Web Pags - Javascript and Ajax
Pags
JavaScript and AJAX
Introduction to JavaScript
Agenda
My Web Site: http://fog.ccsf.edu/~hyip
(download syllabus, class notes).
What is JavaScript?
JavaScript History
JavaScript characteristics
Integrating JavaScript into your web
documents
Objects, Properties, and Methods
What is JavaScript?
JavaScript is an interpreted, object-based scripting
language modeled after C++.
Interpreted languages: an interpreter is needed to
translate a programs statement into machine code.
JavaScript Interpreter is built into Web browsers.
Object-based language: most of client-side
JavaScripts objects come from Web pages such as
images, forms, and form elements.
Scripting languages: are easy to learn, easy to use,
excellent for small routines and applications, and
developed to serve a particular purpose such as
PERL, PHP.
JavaScript is loosely typed language, which means
that variables do not need to have a type specified.
JavaScript History
Client-Side JavaScript
sample
<html>
<head><title>JavaScript sample</title>
</head>
<body>
<h1>Client-side JavaScript sample</h1>
<script language="javaScript" type="text/javascript">
document.write("Hello World! ");
</script>
</body>
</html>
Lexical Structure/Character
Set
The Lexical Structure of a programming language is the set of
elementary rules that specifies how you were program in that
language.
JavaScript programs are written using the Unicode character set.
The 7-bit ASCII encoding is useful only for English.
The 8-bit ISO Latin-1 encoding is useful only for English and
major Western European languages.
The 16-bit Unicode encoding can represent virtually every
written language in common use of the planet.
The ECMAScript v3 standard allows Unicode characters anywhere
in a JavaScript program, version 1 and 2 of the standard allow
Unicode characters only in comments and quoted string literals;
all elements are restricted to the ASCII character set.
Literals/Identifiers
Custom Greeting
<html>
<head><title>Custom Greeting</title>
<script language="JavaScript" type="text/javascript">
/* Global variable */
var visitor = prompt("What is your name?", "");
</script>
</head>
<body>
<h1>Custom Greeting</h1>
<script language="JavaScript" type="text/javascript">
document.write("<h1>Welcome, ", visitor, "</h1>");
</script>
</body>
</html>
Placing JS statements in an
external JS file
An external JS file is a simple text file containing only JS
statements whose name has a .js extension.
Excellent place to declare functions, especially functions
you plan to use again and again with a variety of HTML
documents.
By using an external JS file, you can reduce the overall
loading time of your Web site. The external JS file will
have to transfer only once, the first time the visitor
requests a page that uses it. Any future pages that use
that file can access it from the cache, eliminating the
need to transfer it again.
External JS files also help to hide your code from
pilferers.
Using an external JS file, you can begin building a library
of frequently used functions and routines. Such as
formValidation.js
Real-world
example
JavaScript
example
Object
An item or
thing
pen
document
Properties
An attribute
that describes
an object
pen.inkColor
document.bgC
olor
Method
An action that
can be
performed with
or on an object
pen.write()
document.write
()