Table Of ContentJ S ™
AVA CRIPT
P
FOR ROGRAMMERS
D ® D S
EITEL EVELOPER ERIES
D e i t e l ® S e r
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 Simply C#: An Application-Driven
Tutorial Approach Tutorial Approach
Simply Java™ Programming: An Simply Visual Basic® 2008, 3/E: An
Application-Driven Tutorial Application-Driven Tutorial
Approach Approach
SafariX Web Books
www.deitel.com/books/SafariX.html
C++ How to Program, 5/E & 6/E Small C++ How to Program, 5/E
Java How to Program, 6/E & 7/E Small Java How to Program, 6/E
Simply C++: An Application-Driven Visual Basic 2008 How to Program
Tutorial Approach
Visual C# 2008 How to Program, 3/E
Simply Visual Basic 2008: An
Application-Driven Tutorial
Approach, 3/E
i e s P a g e
Deitel® Developer Series
AJAX, Rich Internet Applications and C# 2008 for Programmers, 3/E
Web Development for Programmers
Java for Programmers
C++ 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:
deitel@deitel.com
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
deitel@deitel.com
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
corpsales@pearsontechgroup.com
For sales outside the U. S., please contact:
International Sales
international@pearsoned.com
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
J S ™
AVA CRIPT FOR
P
ROGRAMMERS
D ® D S
EITEL EVELOPER ERIES
Paul J. Deitel
Deitel & Associates, Inc.
Harvey M. Deitel
Deitel & Associates, Inc.
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 Silverlight Java SE 7 (Dolphin) SharePoint
Functional Programming Visual Basic Resource Center Skype
Regular Expressions Visual C++ JavaFX Web Servers
Visual Studio Team Sys- Wikis
Programming tem Microsoft Windows Vista
ASP.NET 3.5 Web 3D Technologies ASP.NET
Adobe Flex Web Services ASP.NET 3.5 Web 2.0
Ajax Windows Presentation ASP.NET Ajax Alert Services
Apex Foundation C# Attention Economy
ASP.NET Ajax XHTML DotNetNuke (DNN) Blogging
ASP.NET XML Internet Explorer 7 (IE7) Building Web
C Microsoft LINQ Communities
C++ Games and Game .NET Community Generated
C++ Boost Libraries Programming .NET 3.0 Content
C++ Game Programming Computer Game Pro- .NET 3.5 Facebook Developer
C# gramming SharePoint Platform
Code Search Engines and Computer Games Silverlight Facebook Social Ads
Code Sites Mobile Gaming Visual Basic Google Base
Computer Game Sudoku Visual C++ Google Video
Programming Visual Studio Team Google Web Toolkit
CSS 2.1 Internet Business System (GWT)
Dojo Affiliate Programs Windows Presentation Internet Video
Facebook Developer Plat- Competitive Analysis Foundation Joost
form Facebook Social Ads Windows Vista Location-Based Services
Flash 9 Google AdSense Microsoft Popfly Mashups
Functional Programming Google Analytics Microformats
Java Google Services Open Source & Recommender Systems
Java Certification and Internet Advertising LAMP Stack RSS
Assessment Testing Internet Business Apache Social Graph
Java Design Patterns Initiative DotNetNuke (DNN) Social Media
Java EE 5 Internet Public Relations Eclipse Social Networking
Java SE 6 Link Building Firefox Software as a Service
Java SE 7 (Dolphin) Location-Based Services Linux (SaaS)
Resource Center Online Lead Generation MySQL Virtual Worlds
JavaFX Podcasting Open Source Web 2.0
JavaScript Search Engine Optimiza- Perl Web 3.0
JSON tion PHP Widgets
Microsoft LINQ Selling Digital Content Python
Dive Into® Web 2.0
Microsoft Popfly Sitemaps Ruby
.NET Web Analytics eBook
.NET 3.0 Website Monetization Software Web 2 eBook
.NET 3.5 YouTube and AdSense Apache
OpenGL DotNetNuke (DNN) Other Topics
Perl Java Eclipse Computer Games
PHP Java Firefox Computing Jobs
Programming Projects Java Certification and Internet Explorer 7 (IE7) Gadgets and Gizmos
Python Assessment Testing Linux Ring Tones
Regular Expressions Java Design Patterns MySQL Sudoku
Ruby Java EE 5 Open Source
Ruby on Rails Java SE 6 Search Engines
Contents
Preface xv
Before You Begin xxiii
1
Introduction 1
1.1 Introduction 2
1.2 History of the Internet and World Wide Web 3
1.3 World Wide Web Consortium (W3C) 5
1.4 Web 2.0 5
1.5 Key Software Trend: Object Technology 7
1.6 JavaScript: Object-Based Scripting for the Web 8
1.7 Browser Portability 9
1.8 Web Resources 9
2
Introduction to XHTML 10
2.1 Introduction 11
2.2 Editing XHTML 12
2.3 First XHTML Example 12
2.4 W3C XHTML Validation Service 15
2.5 Headings 15
2.6 Linking 16
2.7 Images 19
2.8 Special Characters and Horizontal Rules 22
2.9 Lists 24
2.10 Tables 27
2.11 Forms 31
2.12 Internal Linking 38
2.13 meta Elements 40
2.14 Web Resources 42
3
Cascading Style Sheets™ (CSS) 43
3.1 Introduction 44
3.2 Inline Styles 45
3.3 Embedded Style Sheets 46
3.4 Conflicting Styles 49