-->
Navigation
JavaScript Bible, 5th Edition. Wiley

JavaScript Bible, 5th Edition. Wiley

Now pay Easier and Secure using Paypal
Price:

Read more

Danny Goodman with Michael Morrison

With a foreword by Brendan Eich, JavaScript’s creator

Published by:
Wiley Publishing, Inc.
10475 Crosspoint Blvd.
Indianapolis, Indiana 46256
www.wiley.com

e-books shop
JavaScript Bible, 5th Edition

Praise for Danny Goodman’s JavaScript™ Bible
“JavaScript™ Bible is the definitive resource in JavaScript programming. 
I am never more than three feet from my copy.”
— Steve Reich, CEO, PageCoders
“This book is a must-have for any web developer or programmer.”
—Thoma Lile, President, Kanis Technologies, Inc.
“Outstanding book. I would recommend this book to anyone interested in learning to
develop advanced Web sites. Mr. Goodman did an excellent job of organizing this book
and writing it so that even a beginning programmer can understand it.”
—Jason Hensley, Director of Internet Services, NetVoice, Inc.
“Goodman is always great at delivering clear and concise technical books!”
— Dwayne King, Chief Technology Officer, White Horse
“JavaScript™ Bible is well worth the money spent!”
—Yen C.Y. Leong, IT Director, Moo Mooltimedia, a member of SmartTransact Group
“A must-have book for any internet developer.”
—Uri Fremder, Senior Consultant, TopTier Software
“I love this book! I use it all the time, and it always delivers. 
It’s the only JavaScript book I use!”
—Jason Badger, Web Developer
“Whether you are a professional or a beginner, this is a great book to get.”
— Brant Mutch, Web Application Developer, Wells Fargo Card Services, Inc.
“I never thought I’d ever teach programming before reading your book [JavaScript™
Bible]. It’s so simple to use—the Programming Fundamentals section brought it all back!
Thank you for such a wonderful book, and for breaking through my programming block!”
— Susan Sann Mahon, Certified Lotus Instructor, TechNet Training
“Danny Goodman is very good at leading the reader into the subject. 
JavaScript™ Bible
has everything we could possibly need.”
— Philip Gurdon
“An excellent book that builds solidly from whatever level the reader is at. 
A book that is both witty and educational.”
— Dave Vane
“I continue to use the book on a daily basis and would be lost without it.”
—Mike Warner, Founder, Oak Place Productions
“JavaScript™ Bible is by far the best JavaScript resource I’ve ever seen (and I’ve seen quite a few).”
—Robert J. Mirro, Independent Consultant, RJM Consulting

About the Authors
Danny Goodman is the author of numerous critically acclaimed and best-selling books, including
The Complete HyperCard Handbook, Danny Goodman’s AppleScript Handbook, Dynamic
HTML: The Definitive Reference, and JavaScript & DHTML Cookbook. He is a renowned authority
and expert teacher of computer scripting languages. His writing style and pedagogy continue to
earn praise from readers and teachers around the world. To help keep his finger on the pulse of
real-world programming challenges, Goodman frequently lends his touch as consulting programmer
and designer to leading-edge World Wide Web and intranet sites from his home base
in the San Francisco area.

Michael Morrison is a writer, developer, toy inventor, and author of a variety of books covering
topics such as Java, Web scripting, game development, ActiveX, and Pocket PCs. Some of
Michael’s notable writing projects include Faster Smarter HTML and XML, Teach Yourself XML
in 24 Hours, and The Complete Idiot’s Guide to Java 2. Michael is also the founder of Stalefish
Labs (www.stalefishlabs.com), an entertainment company specializing in traditional
games and toys.

Acknowledgments
Bringing this 1750-page edition up to the current state of the art was a task greater than
one author could possibly handle in a timely manner. While I busied myself with updating
the tutorial and validating terminology and listings with the latest browsers, I was fortunate
to have the tireless help of Michael Morrison—a first-rate author in his own right—who
carefully pruned obsolete content, modernized tens of thousands of lines of code, restored
linearity to the previous edition’s maze, and kept the project on track at a breakneck pace.
David Wall, a long-time JavaScript Bible helper, thankfully contributed his time and expertise
to this effort as well. Many thanks to the hard-working folks at Wiley Publishing: Debra
Williams Cauley, Mary Beth Wakefield, Angela Smith. Above all, I want to thank the many
readers of the earlier editions of this book for investing in this ongoing effort. I wish I had the
space here to acknowledge by name so many who have sent e-mail notes and suggestions:
Your input has been most welcome and greatly appreciated.

Contents at a Glance

Foreword
Preface
Acknowledgments
PART I: Getting Started with JavaScript
Chapter 1: JavaScript’s Role in the World Wide Web and Beyond
Chapter 2: Authoring Challenges Amid the Browser Wars
Chapter 3: Your First JavaScript Script
PART II: JavaScript Tutorial
Chapter 4: Browser and Document Objects
Chapter 5: Scripts and HTML Documents
Chapter 6: Programming Fundamentals, Part I
Chapter 7: Programming Fundamentals, Part II
Chapter 8: Window and Document Objects
Chapter 9: Forms and Form Elements
Chapter 10: Strings, Math, and Dates 
Chapter 11: Scripting Frames and Multiple Windows
Chapter 12: Images and Dynamic HTML
PART III: Document Objects Reference 
Chapter 13: JavaScript Essentials
Chapter 14: Document Object Model Essentials
Chapter 15: Generic HTML Element Objects
Chapter 16: Window and Frame Objects
Chapter 17: Location and History Objects
Chapter 18: The Document and Body Objects
Chapter 19: Link and Anchor Objects
Chapter 20: Image, Area, and Map Objects
Chapter 21: The Form and Related Objects
Chapter 22: Button Objects
Chapter 23: Text-Related Form Objects
Chapter 24: Select, Option, and FileUpload Objects
Chapter 25: Event Objects
Chapter 26: Style Sheet and Style Objects
PART IV: JavaScript Core Language Reference
Chapter 27: The String Object
Chapter 28: The Math, Number, and Boolean Objects
Chapter 29: The Date Object
Chapter 30: The Array Object
Chapter 31: Control Structures and Exception Handling
Chapter 32: JavaScript Operators
Chapter 33: Functions and Custom Objects
Chapter 34: Global Functions and Statements
Chapter 35: Body Text Objects
PART V: Appendixes 
Appendix A: JavaScript and Browser Object Quick Reference
Appendix B: JavaScript Reserved Words
Appendix C: Answers to Tutorial Exercises
Appendix D: JavaScript and DOM Internet Resources
Appendix E: What’s on the CD-ROM
Index
End-User License Agreement
PART VI: Bonus Chapters  . . . On the CD-ROM
Chapter 36: HTML Directive Objects
Chapter 37: Table and List Objects
Chapter 38: The Navigator and Other Environment Objects
Chapter 39: Positioned Objects
Chapter 40: Embedded Objects
Chapter 41: XML Objects
Chapter 42: The Regular Expression and RegExp Objects
Chapter 43: Data-Entry Validation
Chapter 44: Scripting Java Applets and Plug-Ins
Chapter 45: Debugging Scripts
Chapter 46: Security and Netscape Signed Scripts
Chapter 47: Cross-Browser Dynamic HTML Issues
Chapter 48: Internet Explorer Behaviors
Chapter 49: Application: Tables and Calendars
Chapter 50: Application: A Lookup Table
Chapter 51: Application: A “Poor Man’s” Order Form
Chapter 52: Application: Outline-Style Table of Contents
Chapter 53: Application: Calculations and Graphics
Chapter 54: Application: Intelligent “Updated” Flags
Chapter 55: Application: Decision Helper
Chapter 56: Application: Cross-Browser DHTML Map Puzzle
Chapter 57: Application: Transforming XML Data


Screenshot

e-books shop

Purchase Now !
Just with Paypal



Product details
 Price
 File Size
 24,733 KB
 Pages
 1743 p
 File Type
 PDF format
 ISBN
 0-7645-5743-2
 Copyright
 2004 Danny Goodman  

Table of Contents
Foreword . . . . . . vii
Preface . . .. . . . . . ix
Acknowledgments . . . . . . . . xvii
Part I: Getting Started with JavaScript 1
Chapter 1: JavaScript’s Role in the World Wide Web and Beyond . . . . . . . 3
Competing for Web Traffic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Other Web Technologies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
JavaScript: A Language for All . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
JavaScript: The Right Tool for the Right Job . . . . . . . . . . . . . . . . . . . . . . . . 8
Chapter 2: Authoring Challenges Amid the Browser Wars . . . . . . . . . . . 9
Leapfrog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Duck and Cover . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Compatibility Issues Today . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Developing a Scripting Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Chapter 3: Your First JavaScript Script . . . . . . . . . . . . . . . . . . . . . . . 17
The Software Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Setting Up Your Authoring Environment . . . . . . . . . . . . . . . . . . . . . . . . . . 18
What Your First Script Will Do . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Entering Your First Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Examining the Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Have Some Fun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Part II: JavaScript Tutorial 25
Chapter 4: Browser and Document Objects . . . . . . . . . . . . . . . . . . . 27
Scripts Run the Show . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
JavaScript in Action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
The Document Object Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
When a Document Loads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Object References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Node Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
What Defines an Object? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Chapter 5: Scripts and HTML Documents . . . . . . . . . . . . . . . . . . . . . 47
Where Scripts Go in Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
JavaScript Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
When Script Statements Execute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Viewing Script Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Scripting versus Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Chapter 6: Programming Fundamentals, Part I . . . . . . . . . . . . . . . . . 59
What Language Is This? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Working with Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Expressions and Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Data Type Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Chapter 7: Programming Fundamentals, Part II . . . . . . . . . . . . . . . . . 69
Decisions and Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Control Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
About Repeat Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
About Curly Braces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Chapter 8: Window and Document Objects . . . . . . . . . . . . . . . . . . . 83
Top-Level Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
The window Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Window Properties and Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
The location Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
The navigator Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
The document Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Chapter 9: Forms and Form Elements . . . . . . . . . . . . . . . . . . . . . . . 97
The form Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Form Controls as Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
The Button Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
The Checkbox Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
The Radio Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
The select Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Passing Form Data and Elements to Functions . . . . . . . . . . . . . . . . . . . . . 106
Submitting and Prevalidating Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Chapter 10: Strings, Math, and Dates . . . . . . . . . . . . . . . . . . . . . . 111
Core Language Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
String Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
The Math Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
The Date Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Date Calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Chapter 11: Scripting Frames and Multiple Windows . . . . . . . . . . . . . 121
Frames: Parents and Children . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
References among Family Members . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Frame Scripting Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
About iframe Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Controlling Multiple Frames—Navigation Bars . . . . . . . . . . . . . . . . . . . . . 126
References for Multiple Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Chapter 12: Images and Dynamic HTML . . . . . . . . . . . . . . . . . . . . . 131
The Image Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
The javascript: Pseudo-URL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Popular Dynamic HTML Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Part III: Document Objects Reference 141
Chapter 13: JavaScript Essentials . . . . . . . . . . . . . . . . . . . . . . . . . 143
JavaScript Versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Core Language Standard—ECMAScript . . . . . . . . . . . . . . . . . . . . . . . . . 144
Embedding Scripts in HTML Documents . . . . . . . . . . . . . . . . . . . . . . . . . 144
Browser Version Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Designing for Compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Language Essentials for Experienced Programmers . . . . . . . . . . . . . . . . . . 158
Onward to Object Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Chapter 14: Document Object Model Essentials . . . . . . . . . . . . . . . . 163
The Object Model Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
How Document Objects Are Born . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Object Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Object Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Object Event Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Object Model Smorgasbord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Basic Object Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Basic Object Model Plus Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Navigator 4–Only Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Internet Explorer 4+ Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Internet Explorer 5+ Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
The W3C DOM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
Mixing Object Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
Standards Compatibility Modes (DOCTYPE Switching) . . . . . . . . . . . . . . . . 198
Where to Go from Here . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Chapter 15: Generic HTML Element Objects . . . . . . . . . . . . . . . . . . 201
Generic Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Chapter 16: Window and Frame Objects . . . . . . . . . . . . . . . . . . . . 359
Window Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
window Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
frame Element Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462
frameset Element Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468
iframe Element Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474
popup Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 480
Chapter 17: Location and History Objects . . . . . . . . . . . . . . . . . . . 485
location Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485
history Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501
Chapter 18: The Document and Body Objects . . . . . . . . . . . . . . . . . 509
document Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 510
body Element Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576
TreeWalker Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586
Chapter 19: Link and Anchor Objects . . . . . . . . . . . . . . . . . . . . . . 591
Anchor, Link, and a Element Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . 592
Chapter 20: Image, Area, and Map Objects . . . . . . . . . . . . . . . . . . . 601
Image and img Element Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 601
area Element Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621
map Element Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 624
Chapter 21: The Form and Related Objects . . . . . . . . . . . . . . . . . . . 629
The Form in the Object Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629
form Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 630
fieldset and legend Element Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . 646
label Element Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 648
Chapter 22: Button Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . 651
The button Element Object, and the Button, Submit, and Reset Input Objects . . . 651
checkbox Input Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 656
radio Input Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 663
image Input Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669
Chapter 23: Text-Related Form Objects . . . . . . . . . . . . . . . . . . . . . 673
Text Input Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674
password Input Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 689
hidden Input Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 689
textarea Element Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 690
Chapter 24: Select, Option, and FileUpload Objects . . . . . . . . . . . . . 695
select Element Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695
option Element Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 713
optgroup Element Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714
file Input Element Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 717
Chapter 25: Event Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 719
Why “Events”? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 719
Event Propagation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 721
Referencing the event object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 740
event Object Compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 741
Dueling Event Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 742
Event Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 745
NN4 event Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 747
IE4+ event Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 753
NN6+/Moz/Safari event Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 773
Chapter 26: Style Sheet and Style Objects . . . . . . . . . . . . . . . . . . . 793
Making Sense of the Object Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . 794
Imported Stylesheets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 795
Reading Style Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 795
style Element Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 796
styleSheet Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 798
cssRule and rule Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 807
currentStyle , runtimeStyle , and style Objects . . . . . . . . . . . . . . . . . . . . . 810
filter Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 837
Part IV: JavaScript Core Language Reference 847
Chapter 27: The String Object . . . . . . . . . . . . . . . . . . . . . . . . . . . 849
String and Number Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 849
String Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 851
String Utility Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 873
URL String Encoding and Decoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . 876
Chapter 28: The Math, Number, and Boolean Objects . . . . . . . . . . . . 877
Numbers in JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 877
Math Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 883
Number Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 886
Boolean Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 890
Chapter 29: The Date Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . 891
Time Zones and GMT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 891
The Date Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 892
Validating Date Entries in Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 904
Chapter 30: The Array Object . . . . . . . . . . . . . . . . . . . . . . . . . . . 909
Structured Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 909
Creating an Empty Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 910
Populating an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 911
JavaScript Array Creation Enhancements . . . . . . . . . . . . . . . . . . . . . . . . 911
Deleting Array Entries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 912
Parallel Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 912
Multidimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 915
Simulating a Hash Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 916
Array Object Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 916
Array Object Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 918
Chapter 31: Control Structures and Exception Handling . . . . . . . . . . . 931
If and If. . .Else Decisions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 931
Conditional Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 936
Repeat (for) Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 936
The while Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 940
The do-while Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 942
Looping through Properties (for-in) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 942
The with Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 943
Labeled Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 944
The switch Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 946
Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 948
Using try-catch-finally Constructions . . . . . . . . . . . . . . . . . . . . . . . . . . . 950
Throwing Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 953
Error Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 957
Chapter 32: JavaScript Operators . . . . . . . . . . . . . . . . . . . . . . . . . 961
Operator Categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 961
Comparison Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 962
Equality of Disparate Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 963
Connubial Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 965
Assignment Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 967
Boolean Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 968
Bitwise Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 972
Object Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 973
Miscellaneous Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 976
Operator Precedence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 978
Chapter 33: Functions and Custom Objects . . . . . . . . . . . . . . . . . . . 981
Function Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 981
Function Application Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 988
Custom Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 994
Object-Oriented Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1003
Object Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1006
Chapter 34: Global Functions and Statements . . . . . . . . . . . . . . . . 1009
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1010
Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1016
Chapter 35: Body Text Objects . . . . . . . . . . . . . . . . . . . . . . . . . . 1023
blockquote and q Element Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1023
br Element Object. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1024
font Element Object. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1025
h1...h6 Element Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1028
hr Element Object. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1029
label Element Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1033
marquee Element Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1034
Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1038
Event Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1039
Range Object. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1039
selection Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1061
Text and TextNode Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1068
TextRange Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1074
TextRectangle Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1101
Part V: Appendixes 1105
Appendix A: JavaScript and Browser Object Quick Reference . . . . . . . 1107
Appendix B: JavaScript Reserved Words . . . . . . . . . . . . . . . . . . . . 1121
Appendix C: Answers to Tutorial Exercises . . . . . . . . . . . . . . . . . . 1123
Appendix D: JavaScript and DOM Internet Resources . . . . . . . . . . . . 1139
Appendix E: What’s on the CD-ROM . . . . . . . . . . . . . . . . . . . . . . 1143
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1147
End-User License Agreement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1243
Part VI: Bonus Chapters On the CD-ROM
Chapter 36: HTML Directive Objects
Chapter 37: Table and List Objects
Chapter 38: The Navigator and Other Environment Objects
Chapter 39: Positioned Objects
Chapter 40: Embedded Objects
Chapter 41: XML Objects
Chapter 42: The Regular Expression and RegExp Objects
Chapter 43: Data-Entry Validation
Chapter 44: Scripting Java Applets and Plug-Ins
Chapter 45: Debugging Scripts
Chapter 46: Security and Netscape Signed Scripts
Chapter 47: Cross-Browser Dynamic HTML Issues
Chapter 48: Internet Explorer Behaviors
Chapter 49: Application: Tables and Calendars
Chapter 50: Application: A Lookup Table
Chapter 51: Application: A “Poor Man’s” Order Form
Chapter 52: Application: Outline-Style Table of Contents
Chapter 53: Application: Calculations and Graphics
Chapter 54: Application: Intelligent “Updated” Flags
Chapter 55: Application: Decision Helper
Chapter 56: Application: Cross-Browser DHTML Map Puzzle
Chapter 57: Application: Transforming XML Data

  ●▬▬▬▬▬❂❂❂▬▬▬▬▬●
●▬▬❂❂▬▬●
●▬❂▬●

═════ ═════