Home
Scripts
FAQ
Errata
Links
About Us
Buy the Book

Script Examples

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.6 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 4th Edition of the book, click here.

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
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
Chapter 3: Language Essentials
Plug-in detection
Around and around with loops
Writing with loops
Using For/In loops
Using Do/While loops
Checking if Java is enabled
Functions
Multi-level conditionals
Functions that return values
Handling errors
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
Chapter 4: Image Basics
Creating rollovers
Creating more effective rollovers
Putting multiple rollover on a page
Triggering rollovers from a link
Multiple images changing a single rollover
Working with multiple rollovers
Using a function to code multiple images with a single rollover
Using a function to code multiple rollovers
View Source
View Source
View Source
View Source
View Source
View Source
View Source

View Source
Chapter 5: More Fun with Images
Creating cycling banners
Creating multiple cycling 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
Cycling images with random start Displaying multiple random images
Combining a rollover with an image map
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
Chapter 6: 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
Working with iFrames
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
Chapter 7: Working with Browser Windows
Opening a new window
Loading different contents into a window
Opening a new window using an image link
Opening Multiple Windows
Opening Multiple Windows simultaneously
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
View Source
View Source
Chapter 8: Form Handling
Verifying passwords
Using images as submit buttons
Using rollovers as submit buttons
Select and go navigation
Changing menus dynamically
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
View Source
View Source
View Source
Chapter 9: Forms and Regular Expressions
Validating an email address
Validating a file name
Extracting strings
Formatting strings
Formatting and sorting strings
Formatting and validating strings
View Source
View Source
View Source
View Source
View Source
View Source
Chapter 10: Making Your Pages Dynamic
Putting the current date into a Web page
Working with days
Customizing your message for the time of day
Displaying dated by 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 11: 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 12: 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 13: A Brief Introduction to CSS
A page with no styles
Saying it with style
Styles with class
Changing fonts with CSS
Checking your ID
Styles and spans
Distinguished links
Positioning absolutely
View Source
View Source
View Source
View Source
View Source
View Source
View Source
View Source
Chapter 14: 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 15: 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 16: Applied JavaScript
Using an external .js file
Slideshow with captions
Silly Name Generator
Bar Graph Generator
Object-oriented Bar Graph Generator
Font style changer
View Source
View Source
View Source
View Source
View Source
View Source
Chapter 17: Manipulating Nodes
Adding Nodes
Deleting Nodes
Deleting Specific Nodes
Inserting Nodes
Replacing Nodes
View Source
View Source
View Source
View Source
View Source
Chapter 18: Bookmarklets
Your first bookmarklet
Changing a page's background color
Web Safe Colors
Word Lookups (dictionary (short), dictionary (long), and thesaurus)
Viewing images (short, long)
Displaying ISO Latin characters
Converting RGB values to hex
Converting values
A Bookmarklet Calculator
Drag the desired bookmarklet to your Personal Toolbar/Bookmarks Bar/Toolbar Favorites/Links Toolbar.
Chapters 19 and 20 contain no copyable scripts

 

Sponsored advertising: