Home
Scripts
FAQ
Errata
Excerpt
Links
About Us
Buy the Book

Script Examples
For JavaScript for the World Wide Web,
4th Edition: Visual QuickStart Guide

This page gives you access to all of the scripts in our book, listed by chapter and task names. We've given you two ways to use the scripts; if you want to see what a script does, click the name of the script, and a new window will open and run that script. If you want to view the code, or copy it for your own use, click the "View Source" link next to the task.

We've also included the images associated with all of the examples in the book; the images for each task are always below the script for that task when you click one of the "View Source" links. These scripts are presented here for use by owners of our book. Please be aware that you may use the images from this Web site only for the purpose of learning or teaching JavaScript; you may NOT use these images on other Web sites without our express written permission.

If you prefer, you can download all the scripts and images as a single zipped file here (file size is 2.8 Mb). If you need an unzipping utility, we recommend the free Aladdin Expander, available in Mac, Windows, Solaris, and Linux versions.

If you have trouble downloading this file, please wait for a while and then try again; almost every week we get email from a reader reporting trouble downloading, but when we check, all is well. Under no circumstances will we email the zipped file to you; please don't ask.

 

If you are interested in the scripts for the 3rd Edition of the book, click here.

If you are interested in the scripts for the 2nd Edition of the book, click here.

Chapter 1: Getting Acquainted with JavaScript

What JavaScript is

View Source
Chapter 2: Start Me Up!

Where to put your scripts
Hiding scripts from old browsers
Putting comments in scripts
Alerting the user
Confirming the user's choice
Prompting the user
Redirecting the user
Redirecting the user with a link
Browser detection and conditionals
Plug-in detection
Around and around with loops
Writing with loops
Checking if Java is enabled
Functions
Putting more than one script on a page
Scrolling status bars
Status bar messages

View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
Chapter 3: Fun with Images

Creating rollovers
Creating more effective rollovers
Putting more than one rollover on a page
Triggering rollovers from a link
Multiple images changing a single rollover
Working with multiple rollovers
Using a function to simplify coding multiple images with a single rollover
Using a function to simplify coding multiple rollovers
Creating cycling banners
Creating multiple banners
Making the banner cycling wait for the user
Adding links to cycling banners
Building slide shows
Building wraparound slide shows
Displaying a random image
Displaying multiple random images
Combining a rollover with an image map
Automatically changing background colors

View Source
View Source
View Source
View Source
View Source
View Source
View Source

View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
Chapter 4: Frames, Frames, and More Frames

Keeping a page out of a frame
Forcing a page into a frame
Forcing a site into a frame and here
Loading a frame
Creating and loading a dynamic frame
Sharing functions between frames
Storing information in frames
Loading multiple frames at once
Browser detection with frames

View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
Chapter 5: Working with Browser Windows

Opening a new window
Loading different contents into a window
Opening a new window using an image link
Scrolling a window
Updating one window from another
Creating new pages with JavaScript
Closing a window
Creating a control panel
Positioning a window on the screen
Displaying an alert when a window is loaded

View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
Chapter 6: Verifying Forms

Verifying passwords
Select and go navigation
Selecting menu items
Working with radio buttons
Setting one field with another
Validating Zip codes
Validating Email addresses
Complete script

View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
Chapter 7: Forms and Regular Expressions

Validating an email address
Using Regular Expressions to validate a URL
Extracting first/last names with RE
Capitalizing names
Sorting with RE
Formatting with RE

View Source
View Source
View Source
View Source
View Source
View Source
Chapter 8: Making Your Pages Dynamic

Putting the current date into a Web page
Working with days
Customizing your message for the time of day
Displaying the date in a particular time zone
Converting military time to AM/PM
Creating a countdown
Working with referrer pages
Writing text into a document on the fly

View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
Chapter 9: Handling Events

Window Event Handling

onUnload
onResize
onBlur
onFocus

Mouse Event Handling

onMousedown
onMousemove
onDblclick

Form Event Handling

onBlur
onFocus

Key Event Handling

onKeydown



View Source
View Source
View Source
View Source

 

View Source
View Source
View Source



View Source
View Source


View Source

Chapter 10: JavaScript and Cookies

Baking your first cookie
Reading a cookie
Showing your cookies
Using cookies as counters
Deleting cookies
Handling multiple cookies
Displaying "New to You" messages

View Source
View Source
View Source
View Source
View Source
View Source
View Source
Chapter 11: A Brief Introduction to CSS

A page with no styles
Adding styles to a page
How to use a class attribute and here
How to use an ID attribute
How to use a SPAN tag
Changing the appearance of links
Using CSS-P for positioning

View Source
View Source
View Source
View Source
View Source
View Source
View Source
Chapter 12: Working with DHTML

Moving an object in two dimensions (Netscape 4)
Moving an object in two dimensions (IE)
Moving an object in two dimensions (Netscape 6)
Moving an object in two dimensions (cross-browser)
Moving an object in three dimensions (Netscape 4)
Moving an object in three dimensions (IE)
Moving an object in three dimensions (Netscape 6)
Moving an object in three dimensions (cross-browser)
Moving DHTML text (cross-browser)
Modifying a DHTML drop shadow (IE/Win)
Rotating a DHTML shadow (IE/Win)
Modifying a DHTML glow (IE/Win)

View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
Chapter 13: User Interface Design With JavaScript

Pull down menus (cross-platform)
Sliding menus (IE + N6)
Tool tips (cross-platform)
Click Anywhere Form Fields (cross-platform)

View Source
View Source
View Source
View Source
Chapter 14: Applied JavaScript

Using an external .js file
Slideshow with captions
Silly Name Generator
Bar Graph Builder

View Source
View Source
View Source
View Source
Chapter 15: Bookmarklets

Your first bookmarklet
Changing a page's background color
Web Safe Colors
Look up a word (dictionary (short), dictionary (long), and thesaurus)
Viewing images (short), (long)
Displaying ISO Latin characters
Converting RGB values to hex
Converting values
A Bookmarklet Calculator

View Source
View Source
View Source
View Source

View Source
View Source
View Source
View Source
View Source
Chapters 16 and 17 contain no copyable scripts