| Acknowledgments | xv |
| Introduction | xvii |
Part I | Learn JavaScript Basics | |
Chapter 1 | Prepare to Program in JavaScript | 3 |
| Learn the History of JavaScript | 4 |
| The Origin of JavaScript | 5 |
| JavaScript Makes Its Way into Internet Explorer | 5 |
| JavaScript Becomes an Official Standard | 5 |
| Where JavaScript Is Today | 6 |
| Choose a Development Environment | 7 |
| Develop JavaScript-Enabled Web Pages | 7 |
| Create Server-Based Web Applications | 8 |
| Use JavaScript in a DOS or Windows Environment | 9 |
| JavaScript Development Tools | 9 |
| Learn What JavaScript Can and Cannot Do | 13 |
| Use JavaScript as a Client-Side Language | 14 |
| Use JavaScript as a Server-Side Language | 14 |
| Decide Which Version of JavaScript to Use | 15 |
| Test JavaScript Programs Using HTML | 16 |
| Create a JavaScript Template | 16 |
| Understand the JavaScript Template | 18 |
| Communicate with the User | 19 |
| Display an Alert Message | 20 |
| Write Text to the Browser Window | 21 |
| Learn More about Topics Discussed in this Chapter | 22 |
Chapter 2 | Learn JavaScript Fundamentals | 25 |
| Understand Basic Terminology | 26 |
| Store Data in Variables | 26 |
| Define Variables | 27 |
| Define Constants | 28 |
| Understand Program Flow | 29 |
| Control Program Flow with Statements | 30 |
| Execute Code Conditionally | 30 |
| Repeat Statements Using Loops | 34 |
| Comment Your Code | 43 |
| Set a Default Object | 44 |
| Handle Errors | 46 |
| Understand the Basics of Expressions | 49 |
| Use Operators to Create Complex Expressions | 50 |
| Organize Your Code into Functions | 51 |
| Define Functions | 52 |
| Accept Parameters | 54 |
| Understand Variable Scope | 56 |
| Return Values | 58 |
| Use the Improvements in JavaScript 2.0 to Create More Powerful Functions | 59 |
| Use Named Optional Parameters | 60 |
| Accept Any Number of Parameters | 61 |
Chapter 3 | Use Built-in JavaScript Classes | 63 |
| Learn about Objects in JavaScript | 64 |
| Write Unstructured Programs | 65 |
| Organize Code into Procedures | 65 |
| Separate a Program into Modules | 66 |
| Use the Object-Oriented Approach | 66 |
| Turn Properties and Functions into a Class | 68 |
| JavaScript's Built-in Classes and Data Types | 69 |
| Instantiate an Object with the new Operator | 72 |
| Access an Object with the Operator | 73 |
| Access an Object with the [] Operator | 73 |
| Create a String Object in JavaScript | 73 |
| Create a String Object Using a String Literal | 74 |
| Create a String Object Using the String Data Type | 76 |
| Use the String Object's Built-in Functionality | 76 |
| Perform Mathematical Functions | 78 |
| Apply JavaScript's Date-Handling Functions | 79 |
| Convert Strings into Numbers | 82 |
| Use the parseInt and parseFloat Functions | 82 |
| Prepare Text Before Sending to Web Server | 84 |
| Use the escape and unescape Functions | 85 |
| Decide When to Use Regular Expressions | 86 |
| Understand the Basics of Regular Expressions | 87 |
| Create Patterns with a RegExp Object | 89 |
| Understand JavaScript 2.0's Powerful New Data Types | 91 |
| Use the Boolean, Integer, and Number Data Types | 91 |
| Use the char Data Type | 91 |
| Use the Object Data Type | 92 |
| Understand Special Data Types | 92 |
Chapter 4 | Organize Data into Arrays | 95 |
| Create an Array Object | 97 |
| Create an Empty Array | 97 |
| Specify an Initial Array Length | 99 |
| Create and Initialize an Array in One Line of Code | 100 |
| Use Array Literals | 100 |
| Call the Properties and Methods of the Array Object | 101 |
| Set and Retrieve Values in an Array | 104 |
| Use Multidimensional Arrays | 107 |
| Use JavaScript 2.0's Enhanced Arrays | 111 |
| The StaticArray Class | 112 |
| The DynamicArray Class | 114 |
| The ConstArray Class | 114 |
Chapter 5 | Create Your Own JavaScript Classes | 117 |
| Learn about Classes in JavaScript | 118 |
| Create Objects in JavaScript 1.x | 118 |
| Call a Constructor Function | 119 |
| Use an Object Literal | 122 |
| Extend an Existing Class | 123 |
| Extend an Existing Object | 125 |
| Create Objects in JavaScript 2.0 | 126 |
| Define Your Own Classes | 127 |
| Organize Classes Using Inheritance | 130 |
| Choose Between Static and Instance Members | 135 |
| Make Class Members Public or Private | 136 |
Part II | Build JavaScript-Enabled Web Sites | |
Chapter 6 | Embed JavaScript in a Web Page | 141 |
| Understand Basic HTML Structure | 142 |
| Build an HTML Document | 145 |
| Indicate the Document Type with [left angle bracket]!DOCTYPE[right angle bracket] | 146 |
| Add a Title and Define Document Keywords | 147 |
| Format Text with HTML Elements | 148 |
| Format Text with Style Sheets | 150 |
| Use [left angle bracket]script[right angle bracket] to Add JavaScript to a Web Page | 153 |
| Use [left angle bracket]noscript[right angle bracket] for Browsers That Don't Support Scripting | 154 |
| Load an External JavaScript File | 157 |
| Call JavaScript Using Hyperlinks | 158 |
| Learn More about the Topics in this Chapter | 159 |
Chapter 7 | Create Scripts That Work in Every Browser | 161 |
| Understand Browser Differences | 162 |
| What Kind of Errors Can Occur? | 163 |
| Detect What Type of Browser the User Is Running | 164 |
| Query the Document Model | 169 |
| Stick to Web Standards | 170 |
| Write Cross-Browser Code | 171 |
Chapter 8 | Manipulate Web Forms | 179 |
| Understand HTML Forms | 180 |
| Request User Input Using an HTML Form | 181 |
| Process Form Input with Client-Side JavaScript | 182 |
| Process Form Input on a Web Server | 183 |
| Insert an HTML Form into a Web Page | 184 |
| Retrieve and Set Form Control Values in JavaScript | 200 |
| Access Form Values Using the forms Array | 200 |
| Access Form Values Using the elements Array | 202 |
| Access Form Values Using getElementById() | 204 |
| Access Form Values Using getElementsByName() | 204 |
| Access Form Values Using getElementsByTagName() | 205 |
Chapter 9 | Handle Browser Events | 207 |
| Write JavaScript Event Handlers | 208 |
| Handle User Interface Events | 209 |
| Handle Mouse Events | 211 |
| Handle Key Events | 212 |
| Handle HTML Events | 215 |
| Handle Events Using the Event Property | 218 |
| Trigger Events in JavaScript | 219 |
| Call the Method Associated with an Event | 219 |
| Use the fireEvent Method | 220 |
| Overcome Browser Incompatibility | 220 |
Chapter 10 | Communicate Between Browser Frames | 223 |
| Learn the Basics of HTML Frames | 224 |
| Create a Frameset in HTML | 225 |
| Define and Name Frames in a Frameset | 233 |
| Call JavaScript Functions from Other Frames | 235 |
| Access Another Frame Using JavaScript | 236 |
| Call a JavaScript Function Located in Another Frame | 237 |
| Handle Synchronization Between Frames | 239 |
Chapter 11 | Interact with the Web Browser | 243 |
| Learn the Basics of the Document Object Model | 245 |
| Manipulate the Contents of a Web Page | 248 |
| Dynamically Modify the Contents of a Web Page | 249 |
| Change the Items in a Drop-Down List Box | 251 |
| Examine the Entire Browser Window | 252 |
| Retrieve Properties of the Web Browser Software | 254 |
| Examine the Operating System's Display Settings | 256 |
| Access the Web Browser History List | 257 |
| Send the Browser to a New Location | 258 |
Chapter 12 | Perform Simple Animation | 259 |
| Learn the Basics of Cascading Style Sheets | 260 |
| Assign Style to Web Pages Using HTML Elements | 261 |
| Assign Style to Web Pages Using Style Sheets | 264 |
| Use Basic Style Attributes | 268 |
| Position Elements on a Web Page | 268 |
| Modify Styles Using JavaScript | 270 |
| Understand Cross-Platform Issues | 272 |
| Perform Basic Animation Using JavaScript | 274 |
| Dynamically Load Images | 274 |
| Make Content Move Around the Screen | 276 |
Part III | Take JavaScript to the Next Level | |
Chapter 13 | Debug JavaScript Programs | 281 |
| Understand the Possible Causes of Errors | 282 |
| Find the Source of an Error Message | 284 |
| Interpret Error Messages | 285 |
| Use a JavaScript Validator | 287 |
| Add Debugging Code to Your Programs | 287 |
| Use the JavaScript Console | 290 |
| Use a JavaScript Debugger | 291 |
Chapter 14 | Make Your Program Errorproof | 295 |
| Learn the Basics of Exceptions | 296 |
| Catch Exceptions Using the try and catch Statements | 297 |
| Understand Exception Bubbling | 299 |
| Use the IE Error Object | 301 |
| Use Netscape-Only catch Clauses | 302 |
| Use Nonstandard finally Clauses | 302 |
| Create Exceptions Using the throw Statement | 304 |
| Design Programs That Are Easy to Debug from the Start | 306 |
| Avoid Unstructured Programming | 307 |
| Break Code into Manageable Chunks | 307 |
| Reuse Code Using Classes and Objects | 308 |
| Test Your JavaScript Code Thoroughly | 309 |
| Create a Testing Harness | 309 |
| Force Errors to Test Error-Handling Code | 311 |
| Try Your Program in Many Different Environments | 312 |
Chapter 15 | Use JavaScript to Manage Browser Plug-Ins | 313 |
| Insert Scriptable Objects into HTML Web Pages | 315 |
| Include Sun Java Applets | 315 |
| Connect to Java Applets Using JavaScript | 319 |
| Embed Movies and Music in Web Pages | 321 |
| Connect to Music and Media Objects Using JavaScript | 322 |
| Use the Microsoft Calendar Control in Your Web Pages | 324 |
Appendix A | HTML 4.01 Tags | 327 |
Appendix B | JavaScript Quick Reference | 331 |
| Index | 335 |