Sams Teach Yourself JavaScript in 24 Hours 4th Edition Michael Moncur - Quickly access the ebook and start reading today
Sams Teach Yourself JavaScript in 24 Hours 4th Edition Michael Moncur - Quickly access the ebook and start reading today
https://ebookultra.com/download/sams-teach-yourself-macromedia-flash-
mx-2004-in-24-hours-sams-teach-yourself-phillip-kerman/
https://ebookultra.com/download/sams-teach-yourself-to-create-web-
pages-in-24-hours-4th-edition-ned-snell/
https://ebookultra.com/download/swift-in-24-hours-sams-teach-
yourself-2nd-edition-edition-miller/
https://ebookultra.com/download/sams-teach-yourself-tcp-ip-
in-24-hours-2nd-edition-joe-casad/
Sams Teach Yourself ASP NET in 24 Hours 1st Edition Joe
Martin
https://ebookultra.com/download/sams-teach-yourself-asp-net-
in-24-hours-1st-edition-joe-martin/
https://ebookultra.com/download/sams-teach-yourself-android-
application-development-in-24-hours-2nd-edition-lauren-darcey/
https://ebookultra.com/download/sams-teach-yourself-tcp-ip-
in-24-hours-3rd-ed-edition-joe-casad/
https://ebookultra.com/download/sams-teach-yourself-html-and-xhtml-
in-24-hours-5th-edition-dick-oliver/
https://ebookultra.com/download/sams-teach-yourself-microsoft-
expression-web-3-in-24-hours-1st-edition-morten-rand-hendriksen/
Sams Teach Yourself JavaScript in 24 Hours 4th Edition
Michael Moncur Digital Instant Download
Author(s): Michael Moncur
ISBN(s): 9780672328794, 0672328798
File Details: PDF, 4.77 MB
Year: 2010
Language: english
Teach
Yourself
JavaScript
Michael Moncur
in 24
Hours
800 East 96th Street, Indianapolis, Indiana, 46240 USA
Sams Teach Yourself JavaScript in 24 Hours Acquisitions Editor
Betsy Brown
Copyright 2007 by Sams Publishing
All rights reserved. No part of this book shall be reproduced, stored in a Development Editor
retrieval system, or transmitted by any means, electronic, mechanical, Songlin Qiu
photocopying, recording, or otherwise, without written permission from
the publisher. No patent liability is assumed with respect to the use of Managing Editor
the information contained herein. Although every precaution has been Patrick Kanouse
taken in the preparation of this book, the publisher and author assume
no responsibility for errors or omissions. Nor is any liability assumed for Senior Project Editor
damages resulting from the use of the information contained herein. Matthew Purcell
International Standard Book Number: 0-672-32879-8
Copy Editor
Library of Congress Catalog Card Number: 2005909315 Jessica McCarty
Printed in the United States of America
Indexer
First Printing: July 2006
Tim Wright
09 08 07 06 4 3 2 1
Proofreader
Trademarks Carla Lewis
All terms mentioned in this book that are known to be trademarks or
Technical Editor
service marks have been appropriately capitalized. Sams Publishing
Jim O’Donnell
cannot attest to the accuracy of this information. Use of a term in this
book should not be regarded as affecting the validity of any trademark
Publishing Coordinator
or service mark.
Vanessa Evans
Bulk Sales
Sams Publishing offers excellent discounts on this book when ordered in
quantity for bulk purchases or special sales. For more information,
please contact
U.S. Corporate and Government Sales
1-800-382-3419
[email protected]
For sales outside of the U.S., please contact
International Sales
[email protected]
Contents at a Glance
Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433
Table of Contents
Part I: Introducing the Concept of Web Scripting and the JavaScript
Language
Using Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Introducing Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Using Objects to Simplify Scripting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433
About the Author
Michael Moncur is a freelance webmaster and author. He runs a network of websites,
including the Web’s oldest site about famous quotations, online since 1994. He wrote Sams
Teach Yourself DHTML in 24 Hours, and has also written several bestselling books about net-
working, certification programs, and databases. He lives with his wife in Salt Lake City,
Utah.
Dedication
To my family, and especially Laura. Thanks for all your love and support.
Acknowledgments
I’d like to thank everyone at Sams for their help with this book, and for the opportunity to
write it. In particular, Betsy Brown got this edition started and kept it moving. Songlin Qiu
managed the development of the book. Project editor Matt Purcell handled the editing
process, and the copy editor, Jessica McCarty, saved me from many embarrassing errors.
The technical reviewer, Jim O’Donnell, painstakingly tested the scripts and helped keep the
writing grounded in reality.
I am grateful to everyone involved with previous editions of this book, including Scott
Meyers, David Mayhew, Sean Medlock, Susan Hobbs, Michelle Wyner, Jeff Schultz, Amy
Patton, George Nedeff, and Phil Karras. I’d also like to thank Neil Salkind and the rest of
the team at Studio B for their help throughout this project.
Finally, personal thanks go to my wife, Laura; my parents, Gary and Susan Moncur; the
rest of the family; and my friends, particularly Chuck Perkins, Matt Strebe, Cory Storm,
Robert Parsons, Dylan Winslow, Ray Jones, Tyson Jensen, Curt Siffert, Richard Easlick, and
Henry J. Tillman. I couldn’t have done it without your support.
xii
Sams Teach Yourself JavaScript in 24 Hours
You can email 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.
Please note that I cannot help you with technical problems related to the topic of this book, and
that due to the high volume of mail I receive, I might not be able to reply to every message.
When you write, please be sure to include this book’s title and author as well as your name
and phone or email address. I will carefully review your comments and share them with the
author and editors who worked on the book.
Email: [email protected]
Reader Services
Visit our website and register this book at www.samspublishing.com/register for convenient
access to any updates, downloads, or errata that might be available for this book.
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.)
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
Hour 2, “Creating Simple Scripts.”
If you can create a web page with HTML, you can easily use JavaScript to improve a page.
JavaScript programs can range from a single line to a full-scale application. In this book,
you’ll start with simple scripts, and proceed to complex applications, such as a card game.
You’ll also explore some of the most recent uses of JavaScript, such as AJAX remote scripting.
If you’ve spent much time developing pages for the Web, you know that the Web is con-
stantly changing, and it can be hard to keep up with the latest languages and tools. This
book will help you add JavaScript to your web development toolbox, and I think you’ll
enjoy learning it.
Now, thanks to wide browser support for standards established by the W3C (World Wide
Web Consortium) and new technologies such as AJAX, JavaScript’s future is looking brighter
than ever, and a new, more responsible style of scripting is gaining favor. Unobtrusive
scripting focuses on adding interactive features while keeping the HTML simple and
standards-compliant.
2
Sams Teach Yourself JavaScript in 24 Hours
Throughout this book, you’ll learn the best practices for using JavaScript responsibly and fol-
lowing web standards. All of the examples in this book avoid browser-specific techniques in
favor of standard techniques, and all of the examples will work in most modern browsers.
. Part I, “Introducing the Concept of Web Scripting and the JavaScript Language,”
introduces JavaScript, describes how it fits in with other languages, and explains the
basic language features of JavaScript. It also introduces the DOM (Document Object
Model), which connects JavaScript to web documents.
. Part II, “Learning JavaScript Basics,” covers the fundamentals of the JavaScript lan-
guage: variables, functions, objects, loops and conditions, and built-in functions.
You’ll also learn about third-party libraries that add functionality to JavaScript.
. Part III, “Learning More About the DOM,” digs deeper into the DOM objects you’ll use
in nearly every JavaScript program. It covers events, windows, and web forms. You’ll
also learn about CSS style sheets, and the DOM features that enable you to change
styles. Finally, you’ll learn about the W3C DOM, which enables you to modify any
part of a page using JavaScript.
. Part IV, “Working with Advanced JavaScript Features,” begins with a look at unobtrusive
scripting techniques to keep JavaScript from intruding on the functionality and validity
of HTML documents. You’ll also learn how to debug JavaScript applications, and finally
take a look at two cutting-edge JavaScript features: AJAX and Greasemonkey.
. Part VI, “Creating Complex Scripts,” focuses on helping you create complete
JavaScript applications. You’ll learn how to create drop-down menus, a card game
written in JavaScript, and other examples. In the last hour, you’ll learn about what’s
in store for JavaScript and what other languages you might want to learn next.
3
Introduction
These boxes highlight information that can make your JavaScript Did you
programming more efficient and effective. Know?
These boxes provide additional information related to material you just By the
read. Way
These boxes focus your attention on problems or side effects that can Watch
occur in specific situations. Out!
Try It Yourself ▼
The Try It Yourself section at the end of each chapter guides you through the process of
creating your own script or applying the techniques learned throughout the hour. This
will help you create practical applications of JavaScript based on what you’ve learned. ▲
If you have questions or comments about this book, have noticed an error, or have
trouble getting one of the scripts to work, you can also reach the author by email at
[email protected]. (Please check the website first to see if your question has been
answered.)
PART I:
Introducing the Concept of
Web scripting and the
JavaScript Language
The World Wide Web (WWW) began as a text-only medium—the first browsers didn’t even
support images within web pages. Although it’s still not quite ready to give television a
run for its money, the Web has come a long way since then.
Today’s websites can include a wealth of features: graphics, sounds, animation, video, and
occasionally useful content. Web scripting languages, such as JavaScript, are one of the
easiest ways to spice up a web page and to interact with users in new ways.
The first hour of this book introduces the concept of web scripting and the JavaScript lan-
guage. It also describes how JavaScript fits in with other web languages.
If you know how to use HTML (Hypertext Markup Language) to create a web document,
you’ve already worked with one computer language. You use HTML tags to describe how
Other documents randomly have
different content
O Seigneur Dieu!
Her death! I do not wish her death! Not I!
O Our Lady! let not ill thoughts possess me!
I would I were at Morbec this still eve,
Herding the cows amid the golden broom,
Above a sea of glass without a wind,
As stagnant calm as is this prisoned water!
I would gather the musk rose in the lane,
I would tread the wet sand and count the ships,
My brow would not burn, my heart would not ache,
No tears from my eyes would I wipe away!
Why should they not fall like the winter rain?
I am the herd girl here as at Morbec,
And she’s a great lady, loved for herself!
O love! is it love that stifles me so?
O love! is it love that makes me weep?
I thought that love was all splendour and light,
The bow in the sky, the bird at its height,
The glory and state of an angel bright!
What is this pain that burdens all my heart?
[She bows her head upon her knees. The hum of the
street deepens to a continuous and sinister sound.
In the distance a roll of drums. Yvette raises her
head.
The tocsin!
Yvette
Mlle. de Château-Gui
O Ciel!
Would you believe it? O blessed saints above!
The country is in danger!
A Young Girl
Oh! we thought
You brought us news!
[Distant trumpets.
Sister Fidelis
Oh, hush!
The very walls have ears!
Mlle. de Château-Gui
My father says
The King shall have his own again, and all
Will go as merry as a wedding bell!
La patrie est en danger!
De L’Orient
Mesdemoiselles,
One garden of rosebuds time hath not touched!
(To the Sisters.) In your prayers, my Sisters, name Château-Gui!
Ha!
De L’Orient
Count Louis
I have eyes,
De L’Orient!
The Abbé
Hm!—Fair child!
Yvette (coldly)
Citoyen!
Mlle. de Château-Gui
De L’Orient
Sister Fidelis
Monsieur le Comte,
Monsieur the Baron of Morbec did come
To see that all was well with this our charge—
A peasant girl, monsieur, whom he did save
From cold and hunger and ill company.
But now she prospers and we think that he
Will come no more.
Yvette
Jesu Maria!
Ma foi!
He is a soldier is De Vardes! He camps
One day beside the hedgerow in the field!
The next he’s for some royal mount of love,
High as the snow and splendid in the sun!
Since he’s not here I know where else he is!
De L’Orient (sings)
Mignonne, Mignonne!
Kiss me, rose of to-day!
Yvette
Count Louis
Well, well, her mother was as fair as she!
Clarice de Miramand, long-dead Clarice!
Her hair was golden too.—Old times, old times!
And now it is De Vardes and the Marquise!
De L’Orient
Mignonne, Mignonne!
The red rose fades away!
Mignonne, Mignonne!
The white rose will not stay!
The Abbé
Yvette
Citoyen!
The Abbé
Yvette
Citoyen!
The Abbé
A melting eye!
Yvette
Citoyen!
The Abbé
Yvette
Count Louis
De Vardes
Sister Fidelis
Alas!
Mlle. de Château-Gui
O Ciel!
The Abbé
De L’Orient
Sister Simplicia
Alas!
Count Louis
De Vardes
To-night
I ride to Paris.
Yvette
O God!
The Abbé
To Paris!
As well say that you ride to death, De Vardes!
Count Louis
Sister Fidelis
Sister Simplicia
It is so safe in Nantes!
De Vardes
Ah, my Sister,
Because it is so safe in Nantes I go!
Once I did love this people; once I thought
Beyond this Revolution lay the morn,
The dewy morn of a most noble day!
It may be so; I know not; but I am
A soldier of the King. Needs must I go,
My bugles call; I’m breaking camp. Farewell!
Sister Fidelis
De Vardes
If I’m in life I will!
Yvette
Count Louis
Ring on!
Ye bells! ring on to the deaf sky! O France,
Of old thou wast a pleasant land and free,
In palace and in field a courteous place!
Now thou art desolate! Come, Austria, come!
Come, D’Artois, come, Brunswick, and come, Provence!
Rend the tricolour from the breast of France
And plant the fleur-de-lis where stood the Jacobins!
Mlle. de Château-Gui
De Vardes
Not yet,
As far as Vannes I ride beside her coach.
Yvette
Oh!—
Mlle. de Château-Gui
De Vardes (smiling)
Perhaps.
Yvette
Jesu Maria!
Sister Fidelis
Yvette
The Abbé
There will be
A storm to-night!
Count Louis
De Vardes
Yvette
De Vardes
I must.
Yvette
[Lightning.
Oh, see!
The flaming sword before the gates of Eden!
Thou’rt safe within the garden! Go not forth.
Go not to Paris! Stay in Nantes, ah, stay!
Wear the tricolour—
[Thunder.
De Vardes
To-night, Citoyenne!
Ah, thou art skilful at betraying!
Yvette
Quoi!
Sister Benedicta
Yvette
Name of a name!
De Vardes, De Vardes!
You gather the furze while the red rose waits!
De Vardes
At once, my Sister!
[Lightning.
Yvette
De Vardes
De Vardes
And there,
Seest thou not through yonder trees the stone,
The Druid Stone where thou didst lie in sleep?
Yvette
De Vardes
Yvette
De Vardes
Why, yes,
A very lovely name.—Farewell, farewell!
I’ll see thy face, be sure, this very night,
Upon the road before me as I ride.
Yvette
Oh, fare you well beneath the silver moon
As slow you ride beside a lady’s coach,
Discoursing of the dazzling, snowy heights!
I kiss your hand, monseigneur! Fare you well!
The Abbé
De Vardes! De Vardes!
De Vardes
I come!
The Abbé
Yvette
It is too much!
De Vardes
[Distant music.
Yvette
My Duchess Jeanne—
Yvette
De Vardes
Yvette
De Vardes
Yvette
An old wine—
For there dwells a fairy there
Will drag thee down by the long hair,
Mariner, mariner!
De Vardes
The Abbé
De Vardes! De Vardes!
De Vardes
[Exit De Vardes.
Yvette
Monseigneur! ah!
He’s gone! He’s gone to meet the fairy queen!
He’s for the roses and the dazzling peaks!
The seaweed and the furze he’s left behind!
He’s left the storm, he’s left the storm and me!
Voices
O salutaris Hostia!
Quae coeli pandis ostium:
Bella premunt hostilia,
Da robur fer auxilium!
Yvette
[A roll of thunder.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookultra.com