Deitel® Ser

How to Program Series

Java How to Program, 7/E

C++ How to Program, 6/E

Visual C++® 2008 How to Program, 2/E

C How to Program, 5/E

Internet & World Wide Web How to Program, 4/E

Visual Basic® 2008 How to Program

Visual C#® 2008 How to Program, 3/E

Small Java How to Program, 6/E

Small C++ How to Program, 5/E

Simply Series

Simply C++: An Application-Driven Tutorial Approach

Simply Java Programming: An Application-Driven Tutorial Approach

Simply C#: An Application-Driven Tutorial Approach

Simply Visual Basic® 2008, 3/E: An Application-Driven Tutorial Approach

SafariX Web Books

www.deitel.com/books/SafariX.html

C++ How to Program, 5/E & 6/E

Java How to Program, 6/E & 7/E

Simply C++: An Application-Driven Tutorial Approach

Simply Visual Basic 2008: An Application-Driven Tutorial Approach, 3/E

Small C++ How to Program, 5/E

Small Java How to Program, 6/E

Visual Basic 2008 How to Program

Visual C# 2008 How to Program, 3/E

ies Page

Deitel® Developer Series

AJAX, Rich Internet Applications and Web Development for Programmers

C++ for Programmers

C# 2008 for Programmers, 3/E

Java for Programmers

Javascript for Programmers

LiveLessons Video Learning Products

www.deitel.com/books/LiveLessons/

Java Fundamentals Parts 1 and 2

C# Fundamentals Parts 1 and 2

C++ Fundamentals Parts 1 and 2

JavaScript Fundamentals Parts 1 and 2

To follow the Deitel publishing program, please register for the free Deitel® Buzz Online e-mail newsletter at:

www.deitel.com/newsletter/subscribe.html

To communicate with the authors, send e-mail to:

[email protected]

For information on government and corporate Dive-Into® Series on-site seminars offered by Deitel & Associates, Inc. worldwide, visit:

www.deitel.com/training/

or write to

[email protected]

For continuing updates on Prentice Hall/Deitel publications visit:

www.deitel.com
www.prenhall.com/deitel

Check out our Resource Centers for valuable web resources that will help you master Visual C#, other important programming languages, software and Internet- and web-related topics:

www.deitel.com/ResourceCenters.html

Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals.

The authors and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein.

The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests. For more information, please contact:

U. S. Corporate and Government Sales
(800) 382-3419
[email protected]

For sales outside the U. S., please contact:

International Sales
[email protected]

Visit us on the Web: www.phptr.com

Library of Congress Cataloging-in-Publication Data

On file

© 2010 Pearson Education, Inc.

All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permissions, write to:

Pearson Education, Inc.
Rights and Contracts Department
One Lake Street
Upper Saddle River, NJ 07458

ISBN 0-13-700131-2

Text printed in the United States on recycled paper at R.R . Donnelley in Crawfordsville, Indiana.
First printing, February 2009

JavaScript™ for Programmers Deitel® Developer Series

Paul J. Deitel
Deitel & Associates, Inc.

Harvey M. Deitel
Deitel & Associates, Inc.

publisher-image

Upper Saddle River, NJ • Boston • Indianapolis • San Francisco
New York • Toronto • Montreal • London • Munich • Paris • Madrid
Capetown • Sydney • Tokyo • Singapore • Mexico City

Trademarks

DEITEL, the double-thumbs-up bug and DIVE INTO are registered trademarks of Deitel & Associates, Inc.

Apache is a trademark of The Apache Software Foundation.

CSS, DOM, XHTML and XML are registered trademarks of the World Wide Web Consortium.

Firefox is a registered trademark of the Mozilla Foundation.

Google is a trademark of Google, Inc.

JavaScript, Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries.

Microsoft, Internet Explorer and the Windows logo are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.

MySpace is a registered trademark of MySpace.com.

UNIX is a registered trademark of The Open Group.

Web 2.0 is a service mark of CMP Media.

Wikipedia is a registered trademark of WikiMedia.

Throughout this book, trademarks are used. Rather than put a trademark symbol in every occurrence of a trademarked name, we state that we are using the names in an editorial fashion only and to the benefit of the trademark owner, with no intention of infringement of the trademark.

To Brendan Eich:

For creating the JavaScript language while at
Netscape Communications Corporation.

Paul and Harvey Deitel

Deitel Resource Centers

Our Resource Centers focus on the vast amounts of free content available online. Find resources, downloads, tutorials, documentation, books, e-books, journals, articles, blogs, RSS feeds and more on many of today’s hottest programming and technology topics. For the most up-to-date list of our Resource Centers, visit:

www.deitel.com/ResourceCenters.html

Let us know what other Resource Centers you’d like to see! Also, please register for the free Deitel® Buzz Online e-mail newsletter at:

www.deitel.com/newsletter/subscribe.html

Computer Science
Functional Programming
Regular Expressions

Programming
ASP.NET 3.5
Adobe Flex
Ajax
Apex
ASP.NET Ajax
ASP.NET
C
C++
C++ Boost Libraries
C++ Game Programming
C#
Code Search Engines and Code Sites
Computer Game Programming
CSS 2.1
Dojo
Facebook Developer Platform
Flash 9
Functional Programming
Java
Java Certification and Assessment Testing
Java Design Patterns
Java EE 5
Java SE 6
Java SE 7 (Dolphin) Resource Center
JavaFX
JavaScript
JSON
Microsoft LINQ
Microsoft Popfly
.NET
.NET 3.0
.NET 3.5
OpenGL
Perl
PHP
Programming Projects
Python
Regular Expressions
Ruby
Ruby on Rails
Silverlight
Visual Basic
Visual C++
Visual Studio Team System
Web 3D Technologies
Web Services
Windows Presentation Foundation
XHTML
XML

Games and Game Programming
Computer Game Programming
Computer Games
Mobile Gaming
Sudoku

Internet Business
Affiliate Programs
Competitive Analysis
Facebook Social Ads
Google AdSense
Google Analytics
Google Services
Internet Advertising
Internet Business Initiative
Internet Public Relations
Link Building
Location-Based Services
Online Lead Generation
Podcasting
Search Engine Optimization
Selling Digital Content
Sitemaps
Web Analytics
Website Monetization
YouTube and AdSense

Java
Java
Java Certification and Assessment Testing
Java Design Patterns
Java EE 5
Java SE 6
Java SE 7 (Dolphin) Resource Center
JavaFX

Microsoft
ASP.NET
ASP.NET 3.5
ASP.NET Ajax
C#
DotNetNuke (DNN)
Internet Explorer 7 (IE7)
Microsoft LINQ
.NET
.NET 3.0
.NET 3.5
SharePoint
Silverlight
Visual Basic
Visual C++
Visual Studio Team System
Windows Presentation Foundation
Windows Vista
Microsoft Popfly

Open Source & LAMP Stack
Apache
DotNetNuke (DNN)
Eclipse
Firefox
Linux
MySQL
Open Source
Perl
PHP
Python
Ruby

Software
Apache
DotNetNuke (DNN)
Eclipse
Firefox
Internet Explorer 7 (IE7)
Linux
MySQL
Open Source
Search Engines
SharePoint
Skype
Web Servers
Wikis
Windows Vista

Web 2.0
Alert Services
Attention Economy
Blogging
Building Web Communities
Community Generated Content
Facebook Developer Platform
Facebook Social Ads
Google Base
Google Video
Google Web Toolkit (GWT)
Internet Video
Joost
Location-Based Services
Mashups
Microformats
Recommender Systems
RSS
Social Graph
Social Media
Social Networking
Software as a Service (SaaS)
Virtual Worlds
Web 2.0
Web 3.0
Widgets

Dive Into® Web 2.0 eBook
Web 2 eBook

Other Topics
Computer Games
Computing Jobs
Gadgets and Gizmos
Ring Tones
Sudoku

Contents

Preface

Before You Begin

1   Introduction

1.1 Introduction

1.2 History of the Internet and World Wide Web

1.3 World Wide Web Consortium (W3C)

1.4 Web 2.0

1.5 Key Software Trend: Object Technology

1.6 JavaScript: Object-Based Scripting for the Web

1.7 Browser Portability

1.8 Web Resources

2   Introduction to XHTML

2.1 Introduction

2.2 Editing XHTML

2.3 First XHTML Example

2.4 W3C XHTML Validation Service

2.5 Headings

2.6 Linking

2.7 Images

2.8 Special Characters and Horizontal Rules

2.9 Lists

2.10 Tables

2.11 Forms

2.12 Internal Linking

2.13 meta Elements

2.14 Web Resources

3   Cascading Style Sheets™ (CSS)

3.1 Introduction

3.2 Inline Styles

3.3 Embedded Style Sheets

3.4 Conflicting Styles

3.5 Linking External Style Sheets

3.6 Positioning Elements

3.7 Backgrounds

3.8 Element Dimensions

3.9 Box Model and Text Flow

3.10 Media Types

3.11 Building a CSS Drop-Down Menu

3.12 User Style Sheets

3.13 CSS 3

3.14 Web Resources

4   JavaScript: Introduction to Scripting

4.1 Introduction

4.2 Simple Program: Displaying a Line of Text in a Web Page

4.3 Modifying Our First Program

4.4 Obtaining User Input with prompt Dialogs

4.4.1 Dynamic Welcome Page

4.4.2 Adding Integers

4.5 Data Types in JavaScript

4.6 Arithmetic

4.7 Decision Making: Equality and Relational Operators

4.8 Web Resources

5   JavaScript: Control Statements I

5.1 Introduction

5.2 Control Statements

5.3 if Selection Statement

5.4 if...else Selection Statement

5.5 while Repetition Statement

5.6 Counter-Controlled Repetition

5.7 Formulating Algorithms: Sentinel-Controlled Repetition

5.8 Formulating Algorithms: Nested Control Statements

5.9 Assignment Operators

5.10 Increment and Decrement Operators

5.11 Web Resources

6   JavaScript: Control Statements II

6.1 Introduction

6.2 Essentials of Counter-Controlled Repetition

6.3 for Repetition Statement

6.4 Examples Using the for Statement

6.5 switch Multiple-Selection Statement

6.6 do…while Repetition Statement

6.7 break and continue Statements

6.8 Labeled break and continue Statements

6.9 Logical Operators

7   JavaScript: Functions

7.1 Introduction

7.2 Functions

7.3 Programmer-Defined Functions

7.4 Function Definitions

7.5 Random Number Generation

7.6 Example: Game of Chance

7.7 Another Example: Random Image Generator

7.8 Scope Rules

7.9 JavaScript Global Functions

7.10 Recursion

7.11 Recursion vs. Iteration

8   JavaScript: Arrays

8.1 Introduction

8.2 Arrays

8.3 Declaring and Allocating Arrays

8.4 Examples Using Arrays

8.5 Random Image Generator Using Arrays

8.6 References and Reference Parameters

8.7 Passing Arrays to Functions

8.8 Sorting Arrays

8.9 Multidimensional Arrays

8.10 Building an Online Quiz

9   JavaScript: Objects

9.1 Introduction

9.2 Introduction to Object Technology

9.3 Math Object

9.4 String Object

9.4.1 Fundamentals of Characters and Strings

9.4.2 Methods of the String Object

9.4.3 Character-Processing Methods

9.4.4 Searching Methods

9.4.5 Splitting Strings and Obtaining Substrings

9.4.6 XHTML Markup Methods

9.5 Date Object

9.6 Boolean and Number Objects

9.7 document Object

9.8 window Object

9.9 Using Cookies

9.10 Multipage HTML and JavaScript Application

9.11 Using JSON to Represent Objects

10   Document Object Model (DOM): Objects and Collections

10.1 Introduction

10.2 Modeling a Document: DOM Nodes and Trees

10.3 Traversing and Modifying a DOM Tree

10.4 DOM Collections

10.5 Dynamic Styles

10.6 Summary of the DOM Objects and Collections

11   JavaScript: Events

11.1 Introduction

11.2 Registering Event Handlers

11.3 Event onload

11.4 Event onmousemove, the event Object and this

11.5 Rollovers with onmouseover and onmouseout

11.6 Form Processing with onfocus and onblur

11.7 Form Processing with onsubmit and onreset

11.8 Event Bubbling

11.9 More Events

11.10 Web Resources

12   XML and RSS

12.1 Introduction

12.2 XML Basics

12.3 Structuring Data

12.4 XML Namespaces

12.5 Document Type Definitions (DTDs)

12.6 W3C XML Schema Documents

12.7 XML Vocabularies

12.7.1 MathML

12.7.2 Other Markup Languages

12.8 Extensible Stylesheet Language and XSL Transformations

12.9 Document Object Model (DOM)

12.10 RSS

12.11 Web Resources

13   Ajax-Enabled Rich Internet Applications

13.1 Introduction

13.2 Traditional Web Applications vs. Ajax Applications

13.3 Rich Internet Applications (RIAs) with Ajax

13.4 History of Ajax

13.5 “Raw” Ajax Example Using the XMLHttpRequest Object

13.6 Using XML and the DOM

13.7 Creating a Full-Scale Ajax-Enabled Application

13.8 Dojo Toolkit

13.9 Web Resources

A   XHTML Special Characters

B   XHTML Colors

C   JavaScript Operator Precedence Chart

C.1 Operator Precedence Chart

Index

Preface

… the challenges are for the designers of these applications: to forget what we think we know about the limitations of the Web, and begin to imagine a wider, richer range of possibilities. It’s going to be fun.

—Jesse James Garrett, Adaptive Path
   “Ajax: A New Approach to Web Applications”
   (adaptivepath.com/ideas/essays/archives/000385.php)

Introduction

Welcome to JavaScript for Programmers! We’ve worked hard to create what we hope you’ll find to be an informative, entertaining and challenging learning experience. At Deitel & Associates, we write programming language professional books and textbooks for Prentice Hall, deliver corporate training at organizations worldwide and develop Internet businesses.

This book reflects the client side of today’s Web 2.0, Ajax-based, Rich Internet Application-development methodologies. The technologies you’ll learn here are appropriate for experienced professionals who build substantial web-based applications. You’ll find “industrial-strength” code examples that are clear, straightforward and promote best practices.

Today’s users are accustomed to desktop applications with rich graphical user interfaces (GUIs), such as those used on Apple’s Mac OS X systems, Microsoft Windows systems, various Linux systems and others. Users want applications that can run on the Internet and the web and communicate with other applications. Users want to apply database technologies for storing and manipulating their business and personal data. They want applications that are not limited to the desktop or even to some local computer network, but that can integrate Internet and web components, and remote databases. Programmers want to use all these capabilities in a truly portable manner so that applications will run without modification on a variety of platforms.

We focus on the client side of web-based applications (i.e., the portions that typically run in web browsers such as Mozilla’s Firefox, Microsoft’s Internet Explorer, Apple’s Safari, Opera, Google’s Chrome and other web browsers), using technologies such as XHTML, JavaScript, CSS, Extensible Markup Language (XML) the DOM (Document Object Model) and Ajax (Asynchronous JavaScript and XML).

This book was extracted from the front half our Prentice Hall textbook Internet & World Wide Web How to Program, 4/e. That book also provides substantial treatments of key Rich Internet Applications development server-side technologies, including web servers, database, PHP, Ruby on Rails, ASP.NET/ASP.NET Ajax, JavaServer Faces and web services.

Perhaps most important, this book presents over 100 working code examples and shows the outputs produced when these examples are rendered in browsers. We present all concepts in the context of complete working programs. We call this the “live-code approach.” All of the source code is available for download from

www.deitel.com/books/jsfp/

Please see the Before You Begin section following the Preface for details on downloading these examples.

If you have questions as you read this book, send an e-mail to [email protected]—we’ll respond promptly. For updates on the book and the status of all supporting software, and for the latest news on Deitel publications and services, visit www.deitel.com. Sign up at www.deitel.com/newsletter/subscribe.html for the free Deitel® Buzz Online e-mail newsletter and check out www.deitel.com/ResourceCenters.html for our growing list of Internet and web programming, Internet business, Web 2.0 and related Resource Centers. Each week we announce our latest Resource Centers in the newsletter.

Key Features

Here’s some of the key features of JavaScript for Programmers:

• Reflects the client side of today’s Web 2.0, Ajax-based, Rich Internet Application-development methodologies in which you create web applications with the interactivity of desktop applications.

• Covers the two leading web browsers—Internet Explorer and Firefox. All client-side applications in the book run correctly on both browsers.

• Focuses on Web 2.0 technologies and concepts.

• Chapter on building Ajax-enabled web applications with “raw” Ajax and with the Dojo JavaScript libraries. Applications in this chapter demonstrate core Web 2.0 capabilities—partial-page updates and type-ahead.

• Significant treatment of client-side scripting with JavaScript.

• Significant treatments of XHTML DOM manipulation and JavaScript events.

• Significant treatment of XML DOM manipulation with JavaScript.

• Client-side case studies that enable you to interact with preimplemented server-side applications and web services that we host at test.deitel.com.

• Case studies including Deitel Cover Viewer (JavaScript/DOM), Address Book (Ajax) and Calendar (Ajax with the Dojo Toolkit).

All of this has been carefully reviewed distinguished industry developers and academics.

JavaScript for Programmers Achitecture

Figure 1 shows the architecture of JavaScript for Programmers. The book is divided into five parts. The first part, Chapter 1, introduces the Internet, the web and Web 2.0.

Fig. 1 | Architecture of JavaScript for Programmers

Image

The second part, Chapters 23, focuses on the markup (XHTML) and presentation (CSS) technologies that enable you to build web pages. You’ll want to test your web applications across many browsers and platforms. The examples for the book execute correctly on both Microsoft’s Internet Explorer 7 and Mozilla’s Firefox 3 browsers. Most of the examples will also work in other browsers such as Opera, Apple’s Safari and Google’s Chrome, but may not work on earlier browsers. Microsoft Windows users of this book should use Internet Explorer 7 or Firefox 3; readers who have other operating systems should install Firefox 3. Firefox 2 will also work with this book.

The third part of the book, Chapters 411, presents an eight-chapter treatment of JavaScript, including an introduction followed by control statements, functions, arrays and objects. Chapter 10 focuses on the objects and collections that enable you to manipulate web page elements from JavaScript. Chapter 11 demonstrates event handling in JavaScript, which enables you to respond to user interaction with web page elements. Chapters 411 depend on the XHTML and CSS concepts presented in Chapters 23.

The fourth part of the book, Chapter 12, presents XML and RSS—two technologies used frequently in Web 2.0 applications to transmit data between servers and clients. Finally, our presentation concludes with Chapter 13’s treatment of Ajax development. Ajax is not a new technology—we’ve been writing about all but one of its component technologies since the first edition of our book Internet & World Wide Web How to Program in 1999, and many of the technologies existed before that. However, Ajax is one of the key technologies of Web 2.0 and RIAs. The chapter starts with “raw” Ajax development then discusses “encapsulated” Ajax development with the Dojo libraries. Chapters 1213 depend on the concepts presented in Chapters 211.

Teaching Approach

JavaScript for Programmers contains a rich collection of examples. The book concentrates on the principles of good software engineering and stresses program clarity. We are educators who teach leading-edge topics in industry classrooms worldwide. The Deitels have taught courses at all levels to government, industry, military and academic clients of Deitel & Associates, Inc.

Live-Code Approach. JavaScript for Programmers is loaded with “live-code” examples—each new concept is presented in the context of a complete working web application that is immediately followed by one or more screen captures showing the application’s functionality. This style exemplifies the way we teach and write about programming; we call this the “live-code approach.”

Syntax Shading. We syntax shade all the code, similar to the way most integrated-development environments and code editors syntax color code. This improves code readability—an important goal, given that this book contains about 6,000 lines of code in complete, working programs. Our syntax-shading conventions are as follows:

comments appear in italic
keywords appear in bold italic
errors appear in bold black
constants and literal values appear in bold gray

all other code appears in black

Code Highlighting. We place white rectangles around each program’s key code segments.

Using Fonts for Emphasis. We place the key terms and the index’s page reference for each defining occurrence in bold italic text for easier reference. We emphasize on-screen components in the bold Helvetica font (e.g., the File menu) and emphasize program text in the Lucida font (e.g., int x = 5).

Web Access. All of the source-code examples for JavaScript for Programmers are available for download from:

www.deitel.com/books/jsfp/

Site registration is quick, easy and free. Download all the examples, then run each program in a browser as you read the corresponding text discussions. Making changes to the examples and seeing the effects of those changes is a great way to enhance your Internet and web programming learning experience.

Objectives. Each chapter begins with a statement of objectives. This lets you know what to expect and gives you an opportunity to determine if you have met these goals after reading the chapter.

Quotations. The objectives are followed by quotations. Some are humorous, some are philosophical, others offer interesting insights. We hope that you enjoy relating the quotations to the chapter material.

Outline. The chapter outline helps you approach the material in a top-down fashion, so you can anticipate what is to come and set a comfortable learning pace.

Illustrations/Figures. Abundant charts, tables, line drawings, programs and program output are included.

Programming Tips. We include programming tips to help you focus on important aspects of program development. These tips and practices represent the best we have gleaned from a combined seven decades of programming and teaching experience. One of our readers told us that she feels this approach is like the highlighting of axioms, theorems and corollaries in mathematics books—it provides a basis on which to build good software.

Image

Good Programming Practices

Good Programming Practices call attention to techniques that will help you produce programs that are clearer, more understandable and more maintainable.

Image

Common Programming Errors

Pointing out these Common Programming Errors reduces the likelihood that you’ll make the same mistakes.

Image

Error-Prevention Tips

These tips contain suggestions for exposing bugs and removing them from your programs; many describe techniques for preventing bugs in the first place.

Image

Performance Tips

These tips highlight opportunities for making your programs run faster or minimizing the amount of memory that they occupy.

Image

Portability Tips

We include Portability Tips to help you write code that will run on a variety of platforms, and to explain how to achieve a high degree of portability.

Image

Software Engineering Observations

The Software Engineering Observations highlight architectural and design issues that affect the construction of software systems, especially large-scale systems.

Thousands of Index Entries. We’ve included an extensive index which is especially useful when you use the book as a reference.

Deitel® Buzz Online Free E-mail Newsletter

Each week, the free Deitel® Buzz Online newsletter announces our latest Resource Center(s) and includes commentary on industry trends and developments, links to free articles and resources from our published books and upcoming publications, product-release schedules, errata, challenges, anecdotes, information on our corporate instructor-led training courses and more. It’s also a good way for you to keep posted about issues related to JavaScript for Programmers. To subscribe, visit:

www.deitel.com/newsletter/subscribe.html

Deitel Online Resource Centers

Our website, www.deitel.com, provides scores of Resource Centers on various topics including programming languages, software, Web 2.0, Internet business and open source projects. You can view the complete list of Resource Centers in the first few pages of this book or at www.deitel.com/ResourceCenters.html. These Resource Centers evolve out of the research we do to support our books and business endeavors. We list many exceptional (mostly free) resources including tutorials, documentation, software downloads, articles, blogs, podcasts, videos, code samples, books, e-books and more. We announce our latest Resource Centers in the Deitel® Buzz Online.Acknowledgments

It is a great pleasure to acknowledge the efforts of many people whose names may not appear on the cover, but whose hard work, cooperation, friendship and understanding were crucial to the production of the book. Many people at Deitel & Associates, Inc. devoted long hours to this project—thanks especially to Abbey Deitel and Barbara Deitel.

We’d also like to thank the participants in our Honors Internship program who contributed to this publication—Ilana Segall, a mathematical and computational science major at Stanford University; Scott Wehrwein, a computer science major at Middlebury College; and Mark Kagan, a computer science, economics and math major at Brandeis University.

We are fortunate to have worked on this project with the talented and dedicated team of publishing professionals at Prentice Hall. We appreciate the extraordinary efforts of Mark Taub, Editor-in-Chief of Prentice Hall Professional; John Fuller, Managing Editor of Prentice Hall Professional and Marcia Horton, Editorial Director of Prentice Hall’s Engineering and Computer Science Division. Carole Snyder and Dolores Mars did a remarkable job recruiting the book’s review team and managing the review process. Sandra Schroeder and Chuti Prasertsith did a wonderful job designing the book’s cover. Bob Engelhardt and Scott Disanno did a marvelous job managing the book’s production.

This book was adapted from our book Internet & World Wide Web How to Program, 4/e. We wish to acknowledge the efforts of our reviewers on that book who worked on the corresponding chapters. Adhering to a tight time schedule, they scrutinized the text and the programs, providing countless suggestions for improving the accuracy and completeness of the presentation.

Reviewers

Umachitra Damodaran (Sun Microsystems), Vadiraj Deshpande (Sun Microsystems), Molly E. Holtzschlag (W3C), Ralph Hooper (University of Alabama, Tuscaloosa), Johnvey Hwang (Splunk, Inc.), Eric Lawrence (Microsoft), Billy B. L. Lim (Illinois State University), Shobana Mahadevan (Sun Microsystems), Anand Narayanaswamy (Microsoft), John Peterson (Insync and V.I.O., Inc.), Jennifer Powers (University of Albany), José Antonio González Seco (Parlamento de Andalucia), Dr. George Semeczko (Royal & SunAlliance Insurance Canada), Steven Shaffer (Penn State University), Karen Tegtmeyer (Model Technologies, Inc.), Eric M. Wendelin (Auto-trol Technology Corporation), Raymond F. Wisman (Indiana University) and Daniel Zappala (Brigham Young University).

We hope you enjoy this look at the exciting world of JavaScript-based, client-side web applications development. As you read the book, we’d sincerely appreciate your comments, criticisms, corrections and suggestions for improving the text. Please address all correspondence to [email protected]. We’ll respond promptly, and post corrections and clarifications at www.deitel.com/books/jsfp/. We hope you enjoy reading JavaScript for Programmers as much as we enjoyed writing it!

Paul J. Deitel
Dr. Harvey M. Deitel

Maynard, Massachusetts

About the Authors

Paul J. Deitel, CEO and Chief Technical Officer of Deitel & Associates, Inc., has almost three decades of experience in the computer field. Paul is a graduate of MIT’s Sloan School of Management, where he studied Information Technology. Through Deitel & Associates, Inc., he has delivered web programming, Java, C#, Visual Basic, C++ and C courses to industry clients, including Cisco, IBM, Sun Microsystems, Dell, Lucent Technologies, Fidelity, NASA at the Kennedy Space Center, White Sands Missile Range, the National Severe Storm Laboratory, Rogue Wave Software, Boeing, Stratus, Hyperion Software, Adra Systems, Entergy, CableData Systems, Nortel Networks, Puma, iRobot, Invensys and many more. He holds the Sun Certified Java Programmer and Java Developer certifications and has been designated by Sun Microsystems as a Java Champion. He has lectured on Java and C++ for the Boston Chapter of the Association for Computing Machinery. He and his father, Dr. Harvey M. Deitel, are the world’s best-selling programming-language textbook authors.

Dr. Harvey M. Deitel, Chairman and Chief Strategy Officer of Deitel & Associates, Inc., earned B.S. and M.S. degrees from MIT and a Ph.D. from Boston University. He earned tenure and served as the Chairman of the Computer Science Department at Boston College before founding Deitel & Associates, Inc., with his son, Paul J. Deitel. Harvey and Paul are the co-authors of dozens of books and multimedia packages and they are writing many more. The Deitels’ texts have earned international recognition with translations published in Japanese, German, Russian, Spanish, Traditional Chinese, Simplified Chinese, Korean, French, Polish, Italian, Portuguese, Greek, Urdu and Turkish. Dr. Deitel has delivered hundreds of professional seminars to major corporations, academic institutions, government organizations and the military.

About Deitel & Associates, Inc.

Deitel & Associates, Inc., is an internationally recognized corporate training and authoring organization specializing in computer programming languages, Internet and web software technology, object technology education and Internet business development through its Web 2.0 Internet Business Initiative. The company provides instructor-led courses on major programming languages and platforms, such as C++, Java, C, C#, Visual C++, Visual Basic, XML, object technology and Internet and web programming. The founders of Deitel & Associates, Inc. are Paul J. Deitel and Dr. Harvey M. Deitel. The company’s clients include many of the world’s largest companies, government agencies, branches of the military, and academic institutions. Through its 32-year publishing partnership with Prentice Hall, Deitel & Associates, Inc. publishes leading-edge programming professional books, textbooks, interactive multimedia Cyber Classrooms and online and offline LiveLessons video courses. Deitel & Associates, Inc., and the authors can be reached via e-mail at:

[email protected]

To learn more about Deitel & Associates, Inc., its publications and its worldwide Dive Into® Series Corporate Training curriculum, visit:

www.deitel.com/training/

and subscribe to the free Deitel® Buzz Online e-mail newsletter at:

www.deitel.com/newsletter/subscribe.html

Check out the growing list of online Resource Centers at:

www.deitel.com/ResourceCenters.html

Individuals wishing to purchase Deitel publications can do so through:

www.deitel.com/books/index.html

The publisher offers discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests. For more information, please contact:

U. S. Corporate and Government Sales
(800) 382-3419
[email protected]

For sales outside the U. S., please contact:

International Sales
[email protected]

Visit the publisher at www.phptr.com.

Before You Begin

Please follow these instructions to download the book’s examples and ensure you have a current web browser before you begin using this book.

Downloading the JavaScript for Programmers Source Code

The source code in JavaScript for Programmers can be downloaded as a ZIP archive file from www.deitel.com/books/jsfp/. After you register and log in, click the link for the examples under Download Code Examples and Other Premium Content for Registered Users. Extract the example files to your hard disk using a ZIP file extractor program, such as WinZip (www.winzip.com). On Windows, we suggest that you extract the files to a folder such as C:jsfp_examples. On Mac OS X and Linux, we suggest that you extract the files to a folder named jsfp_examples in your home folder.

Web Browsers Used in This Book

We’ve tested every example in this book using Mozilla’s Firefox 2 and 3, and Microsoft’s Internet Explorer 7 web browsers. Before you begin, ensure that you have one or both of these browsers installed on your computer. Internet Explorer 7 is available only for Microsoft Windows operating systems. If you are a Windows user and do not have Internet Explorer 7, you can download it from www.update.microsoft.com using Microsoft’s Windows Update service. Firefox is available for most platforms. You can download Firefox 3 from www.firefox.com.

Many of the book’s examples will not work in Internet Explorer 6. Though most or all of the examples in this book might run on other recent web browsers, such as Opera (www.opera.com), Apple’s Safari (www.apple.com/safari/) and Google’s Chrome (www.google.com/chrome/), we haven’t tested the examples on these or any other browsers.

You are now ready to begin reading JavaScript for Programmers. We hope you enjoy the book! If you have any questions, please e-mail us at [email protected]. We’ll respond promptly.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset