| Foreword | p. xiii |
| About the Author | p. xv |
| About the Technical Reviewer | p. xvii |
| Acknowledgments | p. xix |
| Introduction | p. xxi |
| Getting Started with JavaScript | p. 1 |
| The Why of JavaScript | p. 3 |
| What Is JavaScript? | p. 4 |
| Problems and Merits of JavaScript | p. 5 |
| Why Use JavaScript If It Cannot Be Relied On? | p. 6 |
| JavaScript in a Web Page and Essential Syntax | p. 7 |
| JavaScript Syntax | p. 8 |
| Code Execution | p. 9 |
| An Aside About Functions | p. 11 |
| Objects | p. 12 |
| Simple JavaScript Example | p. 13 |
| Summary | p. 16 |
| Data and Decisions | p. 17 |
| Data, Data Types, and Data Operators | p. 18 |
| The String Data Type | p. 18 |
| Operators | p. 21 |
| JavaScript Variables | p. 23 |
| Converting Different Types of Data | p. 26 |
| The Composite Data Types: Array and Object | p. 30 |
| Objects JavaScript Supplies You with: String, Date, | |
| and Math | p. 30 |
| Arrays | p. 39 |
| The Array Object's Methods and Properties | p. 42 |
| Making Decisions in JavaScript | p. 45 |
| The Logical and Comparison Operators | p. 45 |
| Conditional Statements | p. 49 |
| Testing Multiple Values: the switch Statement | p. 52 |
| Repeating Things: Loops | p. 54 |
| Summary | p. 59 |
| From DHTML to DOM Scripting | p. 61 |
| JavaScript As "the Behavior Layer" | p. 63 |
| Object Detection vs. Browser Dependence | p. 65 |
| Progressive Enhancement | p. 68 |
| JavaScript and Accessibility | p. 69 |
| Good Coding Practices | p. 71 |
| Naming Conventions | p. 71 |
| Code Layout | p. 72 |
| Commenting | p. 74 |
| Functions | p. 76 |
| Short Code via Ternary Operator | p. 79 |
| Sorting and Reuse of Functions | p. 80 |
| Variable and Function Scope | p. 80 |
| Keeping Scripts Safe with the Object Literal | p. 81 |
| Summary | p. 83 |
| HTML and JavaScript | p. 85 |
| The Anatomy of an HTML Document | p. 85 |
| Providing Feedback in Web Pages via JavaScript: | |
| The Old School Ways | p. 89 |
| Using window Methods: prompt(), alert(), | |
| and confirm() | p. 90 |
| Accessing the Document via the DOM | p. 96 |
| Of Children, Parents, Siblings, and Values | p. 99 |
| From the Parents to the Children | p. 100 |
| From the Children to the Parents | p. 102 |
| Among Siblings | p. 103 |
| Changing Attributes of Elements | p. 107 |
| Creating, Removing, and Replacing Elements | p. 109 |
| Avoiding NOSCRIPT | p. 113 |
| Shortening Your Scripts via InnerHTML | p. 115 |
| DOM Summary: Your Cheat Sheet | p. 116 |
| DOMhelp: Our Own Helper Library | p. 118 |
| Summary | p. 122 |
| Presentation and Behavior (CSS and Event Handling) . . 123 | |
| Changing the Presentation Layer via JavaScript | p. 123 |
| Helping the CSS Designer | p. 131 |
| Changing the Document's Behavior via Event Handling | p. 153 |
| Events in the W3C-Compliant World | p. 156 |
| Fixing Events for the Non-W3C-Compliant World | p. 165 |
| Never Stop Optimizing | p. 172 |
| The Ugly Page Load Problem and Its Ugly Solutions | p. 173 |
| Reading and Filtering Keyboard Entries | p. 174 |
| The Dangers of Event Handling | p. 179 |
| Summary | p. 180 |
| Common Uses of JavaScript: Images and Windows | p. 183 |
| Images and JavaScript | p. 183 |
| Basics of Image Scripting | p. 184 |
| Preloading Images | p. 186 |
| Rollover Effects | p. 187 |
| Slide Shows | p. 196 |
| Summary of Images and JavaScript | p. 211 |
| Windows and JavaScript | p. 212 |
| Window Properties | p. 213 |
| Window Methods | p. 215 |
| Summary: Windows and JavaScript | p. 238 |
| Summary | p. 239 |
| JavaScript and User Interaction: Navigation and Forms | p. 241 |
| Navigation and JavaScript | p. 241 |
| The Fear of the Page Reload | p. 242 |
| Basics of Navigation and JavaScript | p. 242 |
| Browser Navigation | p. 245 |
| In-Page Navigation | p. 246 |
| Site Navigation | p. 255 |
| Pagination | p. 263 |
| Summary of Navigation with JavaScript | p. 272 |
| Forms and JavaScript | p. 272 |
| Basics of Forms with JavaScript | p. 274 |
| Form Elements | p. 275 |
| Interactive Forms: Hiding and Showing Dependent Elements | p. 291 |
| Custom Form Elements | p. 297 |
| Summary of Forms and JavaScript | p. 297 |
| Summary | p. 297 |
| Back-End Interaction with Ajax | p. 299 |
| Household Cleaning Liquid, Football Club, or Flash Gordon's | |
| Spacecraft: What Is Ajax? | p. 300 |
| Et Tu, Cache? | p. 309 |
| Putting the X Back into Ajax | p. 309 |
| Replacing XML with JSON | p. 314 |
| Using Server-Side Scripts to Reach Third-Party Content | p. 316 |
| XHR on Slow Connections | p. 320 |
| A Larger Ajax Example: Connected Select Boxes | p. 323 |
| Optional Dynamic Ajax Menus | p. 331 |
| Summary | p. 340 |
| Data Validation Techniques | p. 343 |
| Pros and Cons of Client-Side JavaScript Validation | p. 343 |
| A Quick Reminder About Protecting Content with JavaScript | p. 344 |
| The One-Size-Fits-All Validation Myth | p. 345 |
| Basic JavaScript Validation with String and Numeric Methods | p. 346 |
| String Validation Methods | p. 346 |
| Numeric Validation Methods | p. 352 |
| Regular Expressions | p. 357 |
| Syntax and Attributes | p. 357 |
| Wildcard Searches, Constraining Scope, and Alternatives | p. 358 |
| Restricting the Number of Characters with Quantifiers | p. 359 |
| Word Boundaries, Whitespace, and Other Shortcuts | p. 360 |
| Methods Using Regular Expressions | p. 361 |
| The Power of Parenthesis Grouping | p. 361 |
| Regular Expression Resources | p. 363 |
| Summary of Validation Methods | p. 363 |
| Form Validation Techniques | p. 364 |
| Designating Mandatory Fields | p. 364 |
| The Hidden Field Method | p. 364 |
| The Indicator Element Method | p. 365 |
| The CSS Classes Method | p. 366 |
| The Custom Attribute Method | p. 366 |
| Failures of These Methods | p. 367 |
| Sharing Validation Rules | p. 367 |
| Giving Users Validation Feedback | p. 369 |
| Showing a List of Erroneous Fields | p. 369 |
| Replacing the Main Form with a Clickable Error Message | p. 374 |
| Highlighting Erroneous Fields Individually | p. 376 |
| Instant Validation Feedback | p. 379 |
| Other Dynamic Validation Methods | p. 381 |
| Summary | p. 385 |
| Modern JavaScript Case Study: A Dynamic Gallery | p. 387 |
| Basics of Thumbnail Galleries | p. 387 |
| What Is a Thumbnail Gallery and What Should It Do? | p. 388 |
| Static Thumbnail Galleries | p. 388 |
| Faking Dynamic Galleries with JavaScript | p. 389 |
| Displaying Captions | p. 396 |
| Dynamic Thumbnail Galleries | p. 401 |
| Creating an Image Badge from a Folder | p. 406 |
| Summary | p. 414 |
| Using Third-Party JavaScript | p. 415 |
| What the Web Offers You | p. 415 |
| Code Snippets, RSS Feeds, APIs, and Libraries | p. 416 |
| RSS Feeds and REST APIs | p. 417 |
| Examples of REST APIs | p. 418 |
| Using a Library: Short, Shorter, jQuery | p. 419 |
| Dangers of jQuery and Other Libraries Using Their | |
| Own Syntax | p. 426 |
| Using an API: Adding a Map to Your Site with Google Maps | p. 427 |
| Full Service: The Yahoo Developer Network and User | |
| Interface Library | p. 438 |
| Bouncy Headlines Using YUI | p. 439 |
| Replacing Pop-Up Windows Using the YUI Connection | |
| Manager and Container Components | p. 444 |
| Yahoo User Interface Library Summary | p. 449 |
| Summary | p. 450 |
| Appendix | |
| Debugging JavaScript | p. 451 |
| Common JavaScript Mistakes | p. 451 |
| Misspellings and Case-Sensitivity Issues | p. 451 |
| Trying to Access Undefined Variables | p. 452 |
| Incorrect Number of Closing Braces and Parentheses | p. 454 |
| Concatenation Gone Wrong | p. 456 |
| Assigning Instead of Testing the Value of a Variable | p. 458 |
| Tracing Errors with alert() and "Console" Elements | p. 458 |
| Error Handling with try and catch() | p. 459 |
| Sequential Uncommenting | p. 462 |
| Error Reporting in Browsers | p. 463 |
| Microsoft Internet Explorer 6 | p. 463 |
| Safari | p. 464 |
| Opera 8.5 | p. 466 |
| Firefox 1.5.0.3 | p. 466 |
| JSLint and JSUNIT | p. 470 |
| Summary | p. 470 |
| Index | p. 471 |
| Table of Contents provided by Publisher. All Rights Reserved. |