JavaScript Step by Step 2nd Edition, O'reilly

JavaScript Step by Step 2nd Edition
JavaScript Step by Step 2nd Edition
Steve Suehring

Introducing JavaScript Step by Step,
Second Edition
Much has changed since the first edition of JavaScript Step by Step was written in 2007. 
The underlying JavaScript specification received a major update; Microsoft released Windows
Internet Explorer 8—and now 9 (which is about to be released as I write this); JavaScript
development frameworks have matured and are now ubiquitous; and browsers other than
Internet Explorer and Firefox, such as Safari, Chrome, 
and mobile browsers, became much more popular.
This second edition of JavaScript Step by Step builds on the foundation laid down by the first
edition. The underlying architecture of the JavaScript language is largely the same, but its use
has become pervasive, increasing hugely even in just the last three years. With that in mind,
the layout and coverage of the book have also remained largely the same, with two notable
exceptions: this edition places a much greater emphasis on JavaScript event handling, and it
includes an entirely new section covering JavaScript libraries. 
Specifically, the book focuses on jQuery, which can help simplify JavaScript development, especially on large projects. Throughout the book, you’ll find highlights and additions for the new features in the latest
version of JavaScript. Also, the examples used in the book received greater scrutiny, in multiple
browsers, to reflect the reality of today's web landscape. 
Reader feedback from the first edition is reflected in the content and was the impetus for adding jQuery and emphasizing event handling. The introduction to the first edition is still relevant and applicable,  and so I’ve included it here.
JavaScript is an integral language for web application development, regardless of whether
you’re adding interactivity to a web page or creating an entire application. Today’s web
wouldn’t be the same without JavaScript.
JavaScript is a standards-based language with a formal specification; however, as any web
developer will tell you, almost every web browser interprets that specification differently,
which makes web developers’ jobs more difficult. Fortunately, most web browsers are converging
in their support and interpretation of JavaScript’s core functions.
This book provides an introductory look at JavaScript, including some of its core functions
as well as newer features and paradigms, such as Asynchronous JavaScript and XML (AJAX).
Today’s web users rely on many different platforms and many different browsers to view
web content. This fact was central to development of every aspect of the book, so you’ll see
screenshots in multiple browsers and an emphasis on standards-based, rather than proprietary,
JavaScript development.
The first part of the book examines JavaScript and helps you get started developing JavaScript
applications. You don’t need any specific tools for JavaScript development, so you see how
to create JavaScript files in Microsoft Visual Studio, in Eclipse, and even in Notepad (or any
text editor). Next, the book examines JavaScript’s core language and functions, followed by
an exploration of the relationship between JavaScript and the web browser. 
Finally, you see AJAX demonstrated and see how to build dynamic search forms.

The final part of the book highlights JavaScript frameworks and libraries, giving specific focus to jQuery and jQuery UI.

Acquisitions and Development Editor: Russell Jones
Production Editor: Holly Bauer
Production Services: Online Training Solutions, Inc.
Technical Reviewer: Michael Bazarewsky
Indexing: Potomac Indexing, LLC
Cover: Karen Montgomery
Illustrator: Robert Romano

Contents at a Glance

Part I JavaWhat? The Where, Why, and How of JavaScript
2 Developing in JavaScript . 19
3 JavaScript Syntax and Statements . 49
4 Working with Variables and Data Types . 61
5 Using Operators and Expressions 99
Part II Applying JavaScript
6 Controlling Flow with Conditionals and Loops . 119
7 Working with Functions 147
8 Objects in JavaScript 163
9 The Browser Object Model . 181
Part III Integrating JavaScript into Design
10 The Document Object Model 203
11 JavaScript Events and the Browser 223
12 Creating and Consuming Cookies . 239
13 Working with Images in JavaScript . 253
14 Using JavaScript with Web Forms . 275
15 JavaScript and CSS . 297
16 JavaScript Error Handling . 313
Part IV AJAX and Server-Side Integration
17 JavaScript and XML 331
18 JavaScript Applications . 341
19 A Touch of AJAX 345
20 A Bit Deeper into AJAX . 367
Part V jQuery
21 An Introduction to JavaScript Libraries and Frameworks 383
22 An Introduction to jQuery 387
23 jQuery Effects and Plug-Ins 415
++++++++++++
Table of Contents
Acknowledgements xvii
Introducing JavaScript Step by Step, Second Edition . xix
Getting Help xxii
Part I JavaWhat? The Where, Why, and How of JavaScript
1 JavaScript Is More Than You Might Think
A Brief History of JavaScript 3
Enter Internet Explorer 3.0 4
And Then Came ECMAScript 4
So Many Standards... 5
The DOM 5
What’s in a JavaScript Program? . 6
JavaScript Placement on Your Webpage . 7
What JavaScript Can Do . 10
What JavaScript Can’t Do 10
JavaScript Can’t Be Forced on a Client 10
JavaScript Can’t Guarantee Data Security 11
JavaScript Can’t Cross Domains 11
JavaScript Doesn’t Do Servers 12
Tips for Using JavaScript 12
Where JavaScript Fits 14
Which Browsers Should the Site Support? 15
What’s New in ECMAScript Version 5? 16
New Array Methods . 16
New Controls on Object Properties . 16
New JSON Object . 16
Changes to the Date Object 17
A New Strict Mode . 17
Browser Support . 17
Exercises 17
2 Developing in JavaScript
JavaScript Development Options . 19
Configuring Your Environment . 20
Writing JavaScript with Visual Studio 2010 . 20
Your First Web (and JavaScript) Project with Visual Studio 2010 24
Using External JavaScript Files with Visual Studio 2010 . 28
Writing JavaScript with Eclipse 33
Your First Web (and JavaScript) Project with Eclipse . 33
Using External JavaScript Files with Eclipse 38
Writing JavaScript Without an IDE . 41
Your First Web (and JavaScript) Project with Notepad . 41
Using External JavaScript Files Without an IDE 44
Debugging JavaScript 46
Exercises 47
3 JavaScript Syntax and Statements
A Bit of Housekeeping 49
Case Sensitivity 49
White Space . 50
Comments 51
Semicolons . 51
Line Breaks . 53
Placing JavaScript Correctly 53
JavaScript Statements . 54
What’s in a Statement? 54
The Two Types of JavaScript Statements  55
Reserved Words in JavaScript . 55
A Quick Look at Functions . 56
JavaScript’s New Strict Mode 59
Exercises 60
4 Working with Variables and Data Types
Data Types in JavaScript . 61
Working with Numbers 62
Working with Strings 66
Booleans . 71
Null 71
Undefined 71
Objects 72
Arrays 73
Defining and Using Variables 73
Declaring Variables . 74
Variable Types 74
Variable Scope . 75
The Date Object 82
Using the RegExp Object . 91
The Syntax of Regular Expressions . 92
References and Garbage Collection 96
Learning About Type Conversions . 97
Number Conversions 97
String Conversions 98
Boolean Conversions 98
Exercises 98
5 Using Operators and Expressions
Meet the Operators 99
Additive Operators 99
Multiplicative Operators 100
Bitwise Operators 101
Equality Operators 102
Relational Operators . 104
The in Operator . 105
The instanceof Operator 105
Unary Operators 106
Incrementing and Decrementing . 106
Converting to a Number with the Plus Sign  107
Creating a Negative Number with the Minus Sign . 107
Negating with bitwise not and logical not 107
Using the delete Operator . 108
Returning Variable Types with the typeof Operator . 111
The void Operator . 112
Assignment Operators . 113
The Comma Operator 114
Exercises 115
Part II Applying JavaScript
6 Controlling Flow with Conditionals and Loops
If (and How) 119
Syntax for if Statements . 119
The prompt() Function in Internet Explorer 121
Compound Conditions . 124
Using else if and else Statements . 126
Working with Ternary Conditionals . 131
Testing with switch 132
Looping with while 134
The while Statement . 134
The do...while Statement 135
Using for Loops 137
The for Loop 137
The for...in Loop . 140
The for each...in Loop . 141
Validating Forms with Conditionals . 143
Exercises 145
7 Working with Functions
What’s in a Function? 147
Function Arguments . 148
Variable Scoping Revisited 150
Return Values . 151
More on Calling Functions 152
Anonymous/Unnamed Functions (Function Literals) . 154
Closures 155
Methods 155
A Look at Dialog Functions . 156
Exercises 161
8 Objects in JavaScript
Object-Oriented Development . 163
Objects 163
Properties . 164
Methods . 164
Classes . 164
Creating Objects 167
Adding Properties to Objects . 168
Adding Methods to Objects 171
Finding Out More About Arrays . 171
The length Property 172
Array Methods . 172
Taking Advantage of Built-in Objects 178
The Global Object . 178
Exercises 180
9 The Browser Object Model
Introducing the Browser 181
The Browser Hierarchy . 181
Events 182
A Sense of Self 183
Getting Information About the Screen 185
Using the navigator Object 187
The location Object . 191
The history Object . 198
Exercises 199
Part III Integrating JavaScript into Design
10 The Document Object Model
The Document Object Model Defined 203
DOM Level 0: The Legacy DOM . 204
DOM Levels 1 and 2 . 204
The DOM as a Tree . 205
Working with Nodes 206
Retrieving Elements 206
Retrieving Elements by ID . 206
Retrieving by Tag Name 210
HTML Collections 212
Working with Siblings 212
Working with Attributes . 213
Viewing Attributes 213
Setting Attributes 216
Creating Elements . 217
Adding Text 217
Adding an Element and Setting an ID . 219
Deleting Elements . 219
Exercises 221
11 JavaScript Events and the Browser 
Understanding Window Events 223
The Event Models . 223
A Generic Event Handler 227
Detecting Visitor Information . 228
A Brief Look at the userAgent Property . 229
Feature Testing 230
Keeping JavaScript Away from Older Browsers . 231
Other navigator Properties and Methods 232
Opening, Closing, and Resizing Windows 233
Window Opening Best Practices 234
Opening Tabs: No JavaScript Necessary? . 235
Resizing and Moving Windows 236
Timers 236
Exercises 238
12 Creating and Consuming Cookies
Understanding Cookies 239
Creating Cookies with JavaScript 240
Looking at a Simple Cookie 241
Setting a Cookie’s Expiration Date . 241
Setting the Cookie Path . 245
Setting the Cookie Domain . 246
Working with Secure Cookies . 247
Reading Cookies with JavaScript 248
Removing Cookies 250
Exercises 251
13 Working with Images in JavaScript
Working with Image Rollovers 253
A Simple Rollover 253
Modern Rollovers 255
Preloading Images 262
Working with Slideshows . 263
Creating a Slideshow 263
Moving Backward . 266
Working with Image Maps 270
Exercises 274
14 Using JavaScript with Web Forms
JavaScript and Web Forms . 275
Obtaining Form Data 278
Working with Form Information . 279
Working with Select Boxes 279
Working with Check Boxes 284
Working with Radio Buttons . 287
Prevalidating Form Data 289
Hacking JavaScript Validation . 289
Validating a Text Field 293
Exercises 295
15 JavaScript and CSS
What Is CSS? . 297
Using Properties and Selectors 298
Applying CSS . 299
The Relationship Between JavaScript and CSS . 300
Setting Element Styles by ID . 300
Setting Element Styles by Type 304
Setting CSS Classes with JavaScript 306
Retrieving Element Styles with JavaScript . 307
Modifying Style Sheets with JavaScript . 308
Exercises 311
16 JavaScript Error Handling 
Introducing Two Ways to Handle Errors 313
Using try/catch . 313
And Finally... . 321
Using the onerror Event . 322
Attaching onerror to the window Object 322
Ignoring Errors 324
Attaching onerror to the image Object . 325
Exercises 327
Part IV AJAX and Server-Side Integration
17 JavaScript and XML
Using XML with JavaScript . 331
Looking at an Example XML Document . 331
Loading an XML Document with JavaScript . 332
Working with XML Data from Excel 2007 . 339
A Preview of Things to Come 340
Exercises 340
18 JavaScript Applications
Components of JavaScript Applications 341
The Big Three: Display, Behavior, Data 341
JavaScript and Web Interfaces 342
19 A Touch of AJAX
Introduction to AJAX 345
The XMLHttpRequest Object . 346
Instantiating the XMLHttpRequest Object 346
Sending an AJAX Request . 348
Processing an AJAX Response 350
Processing XML Responses . 354
Working with JSON 355
Processing Headers 356
Using the POST Method 357
Case Study: Live Searching and Updating 359
Exercises 365
20 A Bit Deeper into AJAX
Creating an HTML Table with XML and CSS . 367
Styling the Table with CSS . 371
Changing Style Attributes with JavaScript 371
Creating a Dynamic Drop-Down Box 374
Accepting Input from the User and AJAX . 379
Exercises 380
Part V jQuery
21 An Introduction to JavaScript Libraries and Frameworks
Understanding Programming Libraries 383
Defining Your Own JavaScript Library . 383
Looking at Popular JavaScript Libraries and Frameworks 385
jQuery . 385
Yahoo! User Interface 385
MooTools 386
Other Libraries . 386
Exercises 386
22 An Introduction to jQuery
jQuery Primer 387
Using jQuery 387
The Two jQuery Downloads 387
Including jQuery . 388
Basic jQuery Syntax 388
Connecting jQuery to the Load Event . 389
Using Selectors 391
Selecting Elements by ID . 391
Selecting Elements by Class 391
Selecting Elements by Type 392
Selecting Elements by Hierarchy 392
Selecting Elements by Position . 393
Selecting Elements by Attribute . 396
Selecting Form Elements . 397
More Selectors 397
Functions 397
Traversing the DOM . 398
Working with Attributes 403
Changing Text and HTML 403
Inserting Elements 404
Callback Functions 404
Events 405
Binding and Unbinding 405
Mouse Events and Hover . 407
Many More Event Handlers .  408
AJAX and jQuery . 409
AJAX Errors and Timeouts . 412
Sending Data to the Server . 412
Other Important Options 413
More jQuery . 413
Exercises 414
23 jQuery Effects and Plug-Ins
Core Features for Enhancing Usability 415
Native Effects . 415
jQuery UI 420
Using jQuery UI . 420
Drag and Drop 421
Accordion . 423
More jQuery UI . 427
Exercises 428
Appendix 429
Index . 459

Minimum System Requirements
The code will work on many platforms, including Microsoft Windows, Linux, and Mac.
n Processor A Pentium 133 megahertz (MHz) or greater. (Any computer capable of running a web browser with JavaScript support.)
n Memory 64 megabytes (MB) of RAM or any amount that can run a computer capable of using a web browser with JavaScript support.
n Hard disk 2 MB free hard disk space.
n Operating System Windows 98SE or later, most distributions of Linux, and versions of Mac OS X.
n Display Monitor with 640x480 or higher screen resolution and 16-bit or higher color depth.
n Software Any web browser capable of running JavaScript. Internet Explorer 6 or later,
Mozilla Firefox 2.0 or later, Safari 2 or later, Opera 9, and Konqueror 3.5.2 or later are recommended.

Getting Help
Every effort has been made to ensure the accuracy of this book and the companion content.
If you run into problems, please contact the appropriate source, listed in the following sections,
for help and assistance.

Getting Help with This Book and the Companion Content
If you have questions or concerns about the content of this book or its companion content,
please first search the online Microsoft Press Knowledge Base, which provides support information
for known errors in or corrections to this book, at the following website:
www.microsoft.com/mspress/support/search.asp
If you do not find your answer in the online Knowledge Base, send your comments or questions
to Microsoft Learning Technical Support at:
mspinput@microsoft.com

 Screenshot 

JavaScript Step by Step 2nd Edition, O'reilly

Purchase Now !
Just with Paypal




Product details
 Price
 File Size
 6,658 KB
 Pages
 505 p
 File Type
 PDF format
 ISBN
 978-0-735-64552-3
 Copyright
 2010 Steve Suehring  
●▬▬▬▬▬❂❂❂▬▬▬▬▬●
●▬▬❂❂▬▬●
●▬❂▬●


═════ ═════

Previous Post Next Post