Internet: JavaScript in 3 Minutes.
(from cover of Heinle book)
Computing & Information Services seminar
February 13, 1998, 2-4 p.m., Hewitt 2.
instructor: Jim Cerny
http://unhinfo.unh.edu/NIS/Courses/JS3min/
1. Overview:
Description:
"JavaScript
(JS) is a programming language that you can embed in the HTML
of your Web pages This course ignores the programming and shows
how non-programmers can easily use existing JS from sources on
the Web. Emphasis is on useful JS examples, rather than just
show-off examples. Explains the limitations of JS as well. Lecture/demo
format."
Support statement:
Computing & Information Services offers consulting
support on general Internet usage, on the Netscape browser, and
on HTML. JavaScript is not considered a supported product, but
if you have a question, please ask me anyway.
Goals:
To explain what JavaScript is and is not.
To leave you ready to begin including JavaScript in your Web pages by modifying examples in books and on the Internet.
To point toward major online and print resources
for more information.
2. Background.
Comparison with Java and other languages.
Event-driven model - objects are associated with events.
Objects, methods, properties.
Platform independent, but version and vendor dependencies.
· JS 1.0 (Netscape 2.x), JS 1.1 (Netscape 3.x), JS 1.2 (Communicator 4.x).
· Test scripts with both Netscape 4.x and Explorer 4.x
· There are always bugs.
· Microsoft reverse-engineered JScript and promotes VBScript.
· ECMA proposed standard.
Common reasons to use:
· increase interest of pages.
text banner, changing graphics
· increase interactivity of pages.
forms validation.
· perform a computation.
units conversion, income tax
· identify user characteristics
browser type, connect time, set/read a cookie
· the wow-factor or cool-tool appeal (not
a good reason).
3. Some basic rules and syntax.
Some syntax basics:
· Generally place scripts in the HTML HEAD section.
· // This is a comment line.
· /* This is another comment - useful for comment blocks. */
· JavaScript is case sensitive. Can be tricky.
e.g., "onclick" JS event handler, "onClick" HTML attribute
· Use semicolons to delimit statements.
· Use parentheses () and curly brackets {} as part of function syntax
· Use brackets to enclose function
statements { ... }
The HTML <SCRIPT> ... </SCRIPT> tag - a template:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- hide from older browsers
// place JavaScript code (functions) here ...
// stop hiding -->
</SCRIPT>
</HEAD>
Examples of HTML events to trigger JavaScript code:
<BODY onLoad="thanks()">
document.write("Thanks for
visiting.")
<FORM><INPUT TYPE="button"
VALUE="click here" onClick=doThis></FORM>
<A HREF="contents.html"
onMouseOver="window.status"='welcome and enjoy';
return true;">
blah-blah</A>
javascript:5/2
4. Examples to use and modify in your HTML.
All of these examples are in the "JS3min" course area.
We will have time in class for a handful of examples, leaving
many others for you to explore on your own. In addition there
are many excellent sources of JavaScripts and JavaScript information
on the Web (e.g., Doc JavaScript and Doug Popeney) - plus very
good books.
5. Other comments.
Be patient. Small syntax mistakes can be time consuming to resolve.
Consider an authoring environment (e.g., Dreamweaver).
If you buy a book, check the publisher's Web site for errata.
6. JavaScript books.
These represent the tip of a publications iceberg. In selecting
a book try to think of the kind of book you are looking for in
terms of content (e.g., for programmers or non-programmers; the
whole language or by examples) and style (e.g., formal or informal).
Flanagan, David[1997],
JavaScript: The Definitive Guide, 3rded.,
O'Reilly, paper, 800 pp., $39.95, ISBN:1-56592-392-8
Negrino, Tom, and Smith, Dori, [1998],
JavaScript for the World Wide Web, 2nded.,
Peachpit, paper, 195 pp., $17.95, ISBN:0-201-69648-X.
Heinle, Nick, [1997],
Designing with JavaScript: Creating Dynamic Web Pages,
O'Reilly, paper, 241 pp., $29.95, ISBN:1-56592-300-6.
Lomax, Paul, [1997],
Learning VBScript,
O'Reilly, paper, 598 pp., $39.95, ISBN:1-56592-247-6.
7. Words to Script by.
Nick Heinle, seventeen-year old Wunderkind author, wrote in his epilog:
"First I'll admit something that we all know
but often wish to repress: scripting languages, and the Web, are
evolving all the time. We will never be up to date. Never."
[p. 215]
From Flanagan or somewhere:
"Be generous in what you accept and strict in
what you produce."
jim .cerny@unh.edu
stop me before i click again!
rev. 13-AUG-1998