| Contents | 6 |
---|
| Foreword | 12 |
---|
| About the Author | 13 |
---|
| About the Technical Reviewer | 14 |
---|
| Acknowledgments | 15 |
---|
| Introduction | 16 |
---|
| Chapter 1 Getting Started with JavaScript | 19 |
---|
| The Why of JavaScript | 21 |
| What Is JavaScript? | 22 |
| Problems and Merits of JavaScript | 23 |
| Why Use JavaScript If It Cannot Be Relied On? | 24 |
| JavaScript in a Web Page and Essential Syntax | 25 |
| JavaScript Syntax | 26 |
| Code Execution | 27 |
| An Aside About Functions | 29 |
| Objects | 30 |
| Simple JavaScript Example | 31 |
| Summary | 34 |
| Chapter 2 Data and Decisions | 35 |
---|
| Data, Data Types, and Data Operators | 36 |
| The String Data Type | 36 |
| Operators | 39 |
| JavaScript Variables | 41 |
| Converting Different Types of Data | 44 |
| The Composite Data Types: Array and Object | 48 |
| Objects JavaScript Supplies You with: String, Date, and Math | 48 |
| Arrays | 57 |
| The Array Object s Methods and Properties | 60 |
| Making Decisions in JavaScript | 63 |
| The Logical and Comparison Operators | 63 |
| Conditional Statements | 67 |
| Testing Multiple Values: the switch Statement | 70 |
| Repeating Things: Loops | 72 |
| Summary | 77 |
| Chapter 3 From DHTML to DOM Scripting | 78 |
---|
| JavaScript As the Behavior Layer | 80 |
| Object Detection vs. Browser Dependence | 82 |
| Progressive Enhancement | 85 |
| JavaScript and Accessibility | 86 |
| Good Coding Practices | 88 |
| Naming Conventions | 88 |
| Code Layout | 89 |
| Commenting | 91 |
| Functions | 93 |
| Short Code via Ternary Operator | 96 |
| Sorting and Reuse of Functions | 97 |
| Variable and Function Scope | 97 |
| Keeping Scripts Safe with the Object Literal | 98 |
| Summary | 100 |
| Chapter 4 HTML and JavaScript | 102 |
---|
| The Anatomy of an HTML Document | 102 |
| Providing Feedback in Web Pages via JavaScript: The Old School Ways | 106 |
| Using window Methods: prompt(), alert(), and confirm() | 107 |
| Accessing the Document via the DOM | 113 |
| Of Children, Parents, Siblings, and Values | 116 |
| From the Parents to the Children | 117 |
| From the Children to the Parents | 119 |
| Among Siblings | 120 |
| Changing Attributes of Elements | 124 |
| Creating, Removing, and Replacing Elements | 126 |
| Avoiding NOSCRIPT | 130 |
| Shortening Your Scripts via InnerHTML | 132 |
| DOM Summary: Your Cheat Sheet | 133 |
| DOMhelp: Our Own Helper Library | 135 |
| Summary | 139 |
| Chapter 5 Presentation and Behavior (CSS and Event Handling) | 140 |
---|
| Changing the Presentation Layer via JavaScript | 140 |
| Helping the CSS Designer | 148 |
| Changing the Document s Behavior via Event Handling | 170 |
| Events in the W3C-Compliant World | 173 |
| Fixing Events for the Non-W3C-Compliant World | 182 |
| Never Stop Optimizing | 189 |
| The Ugly Page Load Problem and Its Ugly Solutions | 190 |
| Reading and Filtering Keyboard Entries | 191 |
| The Dangers of Event Handling | 196 |
| Summary | 197 |
| Chapter 6 Common Uses of JavaScript: Images and Windows | 199 |
---|
| Images and JavaScript | 199 |
| Basics of Image Scripting | 200 |
| Preloading Images | 202 |
| Rollover Effects | 203 |
| Slide Shows | 212 |
| Summary of Images and JavaScript | 227 |
| Windows and JavaScript | 228 |
| Window Properties | 229 |
| Window Methods | 231 |
| Summary: Windows and JavaScript | 254 |
| Summary | 255 |
| Chapter 7 JavaScript and User Interaction: Navigation and Forms | 256 |
---|
| Navigation and JavaScript | 256 |
| The Fear of the Page Reload | 257 |
| Basics of Navigation and JavaScript | 257 |
| Browser Navigation | 260 |
| In-Page Navigation | 261 |
| Site Navigation | 270 |
| Pagination | 278 |
| Summary of Navigation with JavaScript | 287 |
| Forms and JavaScript | 287 |
| Basics of Forms with JavaScript | 289 |
| Form Elements | 290 |
| Interactive Forms: Hiding and Showing Dependent Elements | 306 |
| Custom Form Elements | 312 |
| Summary of Forms and JavaScript | 312 |
| Summary | 312 |
| Chapter 8 Back-End Interaction with Ajax | 314 |
---|
| Household Cleaning Liquid, Football Club, or Flash Gordon s Spacecraft: What Is Ajax? | 315 |
| Et Tu, Cache? | 324 |
| Putting the X Back into Ajax | 324 |
| Replacing XML with JSON | 329 |
| Using Server-Side Scripts to Reach Third-Party Content | 331 |
| XHR on Slow Connections | 335 |
| A Larger Ajax Example: Connected Select Boxes | 338 |
| Optional Dynamic Ajax Menus | 346 |
| Summary | 355 |
| Chapter 9 Data Validation Techniques | 357 |
---|
| Pros and Cons of Client-Side JavaScript Validation | 357 |
| A Quick Reminder About Protecting Content with JavaScript | 358 |
| The One-Size-Fits-All Validation Myth | 359 |
| Basic JavaScript Validation with String and Numeric Methods | 360 |
| String Validation Methods | 360 |
| Numeric Validation Methods | 366 |
| Regular Expressions | 371 |
| Syntax and Attributes | 371 |
| Wildcard Searches, Constraining Scope,
|