All other product names and services identified throughout this book are
trademarks or registered trademarks of their respective companies. They are used
throughout this book in editorial fashion only and for the benefit of such
companies. No such uses, or the use of any trade name, is intended to convey
endorsement or other affiliation with the book.
No part of this publication may be reproduced in any form, or stored in a
database or retrieval system, or transmitted or distributed in any form by any
means, electronic, mechanical photocopying, recording, or otherwise, without the
prior written permission of Macmillan Computer Publishing USA, except as
permitted by the Copyright Act of 1976, and except that program listings may be
entered, stored, and executed in a computer system.
THE INFORMATION AND MATERIAL CONTAINED IN THIS BOOK ARE
PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION ANY WARRANTY CONCERNING THE ACCURACY, ADEQUACY, OR
COMPLETENESS OF SUCH INFORMATION OR MATERIAL OR THE RESULTS TO BE OBTAINED FROM
USING SUCH INFORMATION OR MATERIAL. NEITHER MACMILLAN COMPUTER PUBLISHING USA
NOR THE AUTHOR SHALL BE RESPONSIBLE FOR ANY CLAIMS ATTRIBUTABLE TO ERRORS,
OMISSIONS, OR OTHER INACCURACIES IN THE INFORMATION OR MATERIAL CONTAINED IN
THIS BOOK, AND IN NO EVENT SHALL MACMILLAN COMPUTER PUBLISHING USA OR THE AUTHOR
BE LIABLE FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
ARISING OUT OF THE USE OF SUCH INFORMATION OR MATERIAL.
ISBN 1-56276-423-3
Acknowledgments
I thank the superb people I worked with at Ziff-Davis-Stacy Hiquet, Suzanne
Anthony, Kelly Green, and Barbara Dahl. I thank my incredible editors, Deborah
Craig and Luke Cassady-Dorion, without whom this book never would have made it
into your hands. I thank my colleagues at Fujitsu Network Switching, who put up
with my demented ramblings about the wonders of JavaScript. I thank Chelsea and
Trevor for once more putting up with a daddy who never seems to get enough sleep
and who is constantly working on the book-again. I thank Joan for putting up
with my schedule, and for getting the ball rolling on yet another book, even
though she knew what that entailed and the sacrifices she'd have to make-been
there, done that, and did it again anyway. Finally, I thank the Lord for this
experience, and I thank the woman who taught me to thank Him, even when I don't
understand why-Martha Ilene Larson Whitaker. I dedicate this book to her memory.
This is a book about writing exciting Web pages with JavaScript. Before
JavaScript or its ancestor, LiveScript, Web pages were written in HTML. The
pages could be very sophisticated in their layout, but they just sat there.
JavaScript can make your Web pages come alive. Your Web pages can now be
dynamic, changing before the user's eyes. JavaScript can make your Web pages
both more interesting and more fun.
JavaScript isn't very difficult to learn. I myself picked up the basics in a
matter of hours. You can, too.
You don't need to read this book cover to cover, and you don't have to read
the chapters in any particular order. Skip around, read what seems interesting,
and write some code. It's the best way to learn. You will need a copy of
Netscape Navigator, preferably version 2.01 or later, but that's all. I use
WebMania! to write some of my code, because it takes care of a lot of the
details that I might forget, but all you really need is a simple ASCII text
editor-vi, emacs, Notepad, whatever.
This book is divided into three parts. The first part includes three
chapters. Chapter
1is a quick introduction to JavaScript that describes what it is and where
it came from. Chapter
2explains what JavaScript is good for, outlining what you can do with it. Chapter
3lets me get up on my soapbox and do a little preaching about what makes a
good Web page, what makes a bad Web page, and what you can do to keep your pages
on the good list.
The second section consists of six chapters, all of which contain a complete
JavaScript Web page. Each chapter introduces a problem, demonstrates how you
might solve it without JavaScript, and then shows how you can craft a much
better solution with JavaScript. These chapters all conclude with some thoughts
on how you can enhance the solution and how you can adapt the techniques to
creating your own Web pages with JavaScript. In every chapter, the JavaScript
code is discussed in depth, function by function. No mysteries; there's no one
behind the curtain. If you don't understand something about the code, write me
at marcj@nando.net. I'll be glad to answer
your questions!
Finally, the third section contains six appendices, chock full of useful
reference material: the character set, reserved words, a review of HTML, the
JavaScript operators, JavaScript's built-in objects and functions, and online
resources. Again, if there's something I missed, write me. I want to help.
This book was written on a nameless 486-based desktop system lovingly
assembled by Computer Options of Raleigh, North Carolina, and on a Pentium-based
Samsung notebook, using Microsoft Word for Windows 6.0 under Windows 3.1 (the
desktop) and Windows 95 (the notebook). The Web pages created were tested on
both platforms, as well as on a Sun Microsystems Sparc-10 running Solaris 2.4
and on the desktop system under Linux 1.2.1. Luke Cassady-Dorion, my excellent
technical editor, also ran them on his Macintosh. The Web pages were written
with WebMania! 1.5. Screen shots were taken with Collage Complete 1.0, and
enhanced with Paint Shop Pro 3.12. My Web space provider is Hurricane Electric (he.net;
my home page is http://www.he.net/~marcj/index.phpl),
and the Web pages were loaded onto their server for live testing. All of this
was accomplished through my Internet service provider, nando.net.
I had a lot of fun writing this book, and I hope it proves to be a useful
addition to your library.