Ebook banner rotater for Web Programming and Administration

Laura Lemay's Web Workshop

JavaScript

by Laura Lemay and Michael G. Moncur


C  O  N  T  E  N  T  S


Introduction

Chapter 1   Creating Simple JavaScript Programs

Chapter 2   Working with Larger Programs and Variables

Chapter 3   Working with Objects and Events

Chapter 4   Using Built-In Objects and Custom Objects

Chapter 5   Accessing Window Elements as Objects

Chapter 6   Using Interactive Forms

Chapter 7   Real-Life Examples I

Chapter 8   Improving a Web Page with JavaScript

Chapter 9   Using Frames, Cookies, and Other Advanced Features

Chapter 10   Working with Multiple Pages and Data

Chapter 11   Real-Life Examples II

Chapter 12   Working with Graphics in JavaScript

Chapter 13   Working with Multimedia and Plug-Ins

Chapter 14   Debugging JavaScript Programs

Chapter 15   Real-Life Examples III

Chapter 16   Integrating JavaScript with Java

Chapter 17   Combining JavaScript, CGI, and SSI

Chapter 18   Using ActiveX and Microsoft Internet Explorer 3.0

Chapter 19   Real-Life Examples IV

Chapter 20   The Future of JavaScript

appendix A   JavaScript Structure and Objects Reference

appendix B   JavaScript Statements, Functions, Operators, and Keywords Reference

appendix C   Online JavaScript Resources


Credits


Copyright © 1996 by Sams.net Publishing

FIRST EDITION

All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Neither is any liability assumed for damages resulting from the use of the information contained herein. For information, address Sams.net Publishing, 201 W. 103rd St., Indianapolis, IN 46290.

International Standard Book Number: 1-57521-141-6


HTML conversion by :
    M/s. LeafWriters (India) Pvt. Ltd.
    Website : http://leaf.stpn.soft.net
    e-mail : leafwriters@leaf.stpn.soft.net


President, Sams Publishing: Richard K. Swadley
Publishing Manager Mark Taber
Managing Editor: Cindy Morrow
Director of Marketing: John Pierce
Assistant Marketing Managers: Kristina Perry, Rachel Wolfe


Acquisitions Editor Mark Taber Development Editor Fran Hatton
Software Development Specialist Bob Correll Production Editor Nancy Albright
IndexerCharlotte Clapp Technical Reviewer Jeff Shockley
Editorial Coordinator Bill Whitmer Technical Edit Coordinator Lorraine Schaffer
Resource Coordinator Deborah Frisby Editorial Assistants Carol Ackerman, Andi Richter, Rhonda Tinch-Mize
Cover Designer Alyssa YeshBook Designer Alyssa Yesh
Copy Writer Peter FullerProduction Team Supervisor Brad Chinn
ProductionStephen Adams, Debra Bolhuis, Mona Brown, Bruce Clingaman, Jason Hand, Daniel Harris, Ayanna Lacey, Clint Lahnen, Laura Robbins, Susan Van Ness


Acknowledgments

I'd like to thank everyone involved in the production of this book. Mark Taber at Sams.net helped fine-tune the initial proposal and got the project off the ground, and he's been involved at every stage. Mark always has time for my questions and has been a great help. Kelly Murdock and Fran Hatton were very helpful in fine-tuning the outline.

Fran also made many helpful comments in the editing stage. I'd like to thank the editor, Nancy Albright, for her comments and edits, which made things much more readable. Deborah Frisby helped to keep the editing process moving along.

I'd like to thank the Software Specialist for this book, Bob Correll, who was very helpful in putting together the content of the CD-ROM. I'd also like to thank the rest of the staff at Sams.net for their help in publishing this book.

Laura Lemay deserves mention for writing the great HTML books that launched the Web Workshop series.

Thanks to Netscape for giving me something to write about, and specifically to Brendan Eich, who goes above and beyond the call of duty in answering questions. I'd also like to thank all the participants in the JavaScript newsgroups and mailing lists; their answers helped me learn JavaScript, and their questions helped me know what to write about.

Finally, personal thanks go to my wife, Laura, my parents, Gary and Susan Moncur, the rest of my family, and my friends, particularly Chuck Perkins, Matt Strebe, Cory Storm, Robert Parsons, Dylan Winslow, James Chellis, Curt Siffert, and Henry J. Tillman. I couldn't have done it without your support.


About the Author

Michael Moncur is the owner of Starling Technologies, a consulting firm specializing in networking and the Internet. He is also a freelance webmaster and author, and has worked with the Internet since 1989. He has written several bestselling books about Novell networks.


Tell Us What You Think!

As a reader, you are the most important critic and commentator of our books. We value your opinion and want to know what we're doing right, what we could do better, what areas you'd like to see us publish in, and any other words of wisdom you're willing to pass our way. You can help us make strong books that meet your needs and give you the computer guidance you require.

Do you have access to CompuServe or the World Wide Web? Then check out our CompuServe forum by typing GO SAMS at any prompt. If you prefer the World Wide Web, check out our site at http://www.mcp.com.

Note
If you have a technical question about this book, call the technical support line at (800) 571-5840, ext. 3668.

As the team leader of the group that created this book, I welcome your comments. You can fax, e-mail, or write me directly to let me know what you did or didn't like about this book-as well as what we can do to make our books stronger. Here's the information:

FAX:317/581-4669
E-mail:newtech_mgr@sams.mcp.com
Mail:Mark Taber
Sams Publishing
201 W. 103rd Street
Indianapolis, IN 46290


Introduction

The World Wide Web began as a simple repository for information, but it has grown into much more-it entertains, teaches, advertises, and communicates. As the Web has evolved, the tools have also evolved. Simple markup tools such as HTML have been joined by true programming languages-including JavaScript.

Now don't let the word "programming" scare you. For many, the term conjures up images of long nights staring at the screen, trying to remember which sequence of punctuation marks will produce the effect you need. (Don't get me wrong. Some of us enjoy that sort of thing-and that's fine too.)

Although JavaScript is programming, it's a very simple language. As a matter of fact, if you haven't programmed before, it makes a great introduction to programming. It requires very little knowledge to start programming with JavaScript-you'll write your first program in Chapter 1, "Creating Simple JavaScript Programs."

If you have programmed in other languages, you'll find JavaScript interesting-it's a language with very few solid rules. The syntax is easy to master, and programming with JavaScript can actually be fun. I've programmed in many languages, and I've found that I can write a truly useful, rewarding application in JavaScript in only an hour or two-with other languages, it often takes days before you see the first actual result of the program.

JavaScript can do all sorts of things to liven up Web pages, and you can even create entire applications that span multiple pages. This book covers them all-serious business applications, gadgets such as scrolling messages, and even games.

Of course, every language has its limitations, and JavaScript is no exception-if it could do everything, it wouldn't be easy to learn. Throughout this book I've pointed out the areas where JavaScript falls short. I also introduce the tools you can use to fill the gaps in JavaScript-CGI, SSI, and Java.

If you've spent much time developing pages for the Web, you know that the Web is constantly changing, and it can be hard to keep up with the latest features. This book will help you add JavaScript to your Web development toolbox, and I think you'll enjoy learning it.

I really had fun writing this book-and believe it or not, writing isn't always fun. I hope you'll have as much fun as you experiment with JavaScript and its capabilities.

Who Should Read This Book

If you want to learn how to enhance your Web pages with JavaScript, this book is for you. I have made a few assumptions, though:

Note
Although they're often confused, JavaScript and Java are very different languages. Although we introduce Java and explain how to connect it with JavaScript, this is primarily a book about JavaScript.

How to Read This Book

This book is divided into six parts, roughly organized according to the complexity of their subjects:

Although this book is organized so that it can be read from cover to cover, you don't need to. You'll want to read Chapter 1 to understand the basic concepts of JavaScript, but you can then skip around as you please. At the end of each chapter you'll find a list of next steps-other chapters to continue your learning, not necessarily in order.

Throughout this book you'll find Tasks, which show you how to use a particular JavaScript feature and include a working example application. The applications range from simple gadgets to business applications to games and graphics.

A Note About Software

JavaScript-like most Web-related languages and products-is constantly evolving. As it has grown in popularity, features have been added and changes have been made. Because of this, which browser you use can affect how well things work.

The examples in this book were developed with Netscape 3.0, and have all been tested on the final version of 3.0. Where possible, I've made every effort to ensure that they'll work on earlier versions, but I recommend that you download the latest version to be sure everything will work.

You may also run into problems if you use a newer browser-needless to say, I wasn't able to test the examples on programs that didn't exist at this writing. Don't download an earlier version, though-my recommendation is to keep the latest version, but consult this book's Web site (see address later in this Introduction) to find out how things have changed.

Keeping in Touch

I can't update your copy of this book each time JavaScript changes, but I've done the next best thing. I've set up a Web site devoted to this book. Here's the URL:

http://www.starlingtech.com/books/javascript/

At this site, you'll find online versions of all the examples in this book and a variety of additional examples demonstrating JavaScript's features. You will also find information about the latest new JavaScript features and how you can adapt the examples or your own programs to use them.

If you have any questions or comments about this book and its content, check the Web site for additional information. If you don't find what you need there, feel free to contact me directly via e-mail at this address:

jsbooks@starlingtech.com

If you have trouble getting one of the programs in this book to work, or with your own programs, first check out the online resources in appendix C. If that doesn't help, feel free to contact me and I'll try to help; be warned, though, that it may take me a week or two to dig myself out from my current pile of e-mail to reply.

Last but not least, if you've created a JavaScript application that you're proud of, I'd like to see it. Send the URL to the e-mail address above. I'll post links to some of the best applications created by readers on the Web site.