Tables of Contents for Javascript and Dhtml Cookbook
Concatenating (Joining) Strings
4
2
Testing Equality of Two Strings
8
2
Testing String Containment Without Regular Expressions
10
1
Testing String Containment with Regular Expressions
11
2
Searching and Replacing Substrings
13
1
Using Special and Escaped Characters
14
2
Reading and Writing Strings for Cookies
16
3
Converting Between Unicode Values and String Characters
19
1
Encoding and Decoding URL Strings
20
2
Encoding and Decoding Base64 Strings
22
4
Converting Between Numbers and Strings
30
2
Testing a Number's Validity
32
1
Testing Numeric Equality
33
1
Rounding Floating-Point Numbers
34
1
Formatting Numbers for Text Display
35
3
Converting Between Decimal and Hexadecimal Numbers
38
2
Generating Pseudorandom Numbers
40
1
Calculating Trigonometric Functions
41
1
Creating a Date Object
41
2
Calculating a Previous or Future Date
43
1
Calculating the Number of Days Between Two Dates
44
2
Creating a Simple Array
53
1
Creating a Multidimensional Array
54
2
Converting Between Arrays and Strings
56
2
Doing Something with the Items in an Array
58
2
Sorting a Simple Array
60
1
Creating a Custom Object
64
4
Simulating a Hash Table for Fast Array Lookup
68
2
Doing Something with a Property of an Object
70
1
Sorting an Array of Objects
71
1
Customizing an Object's Prototype
72
5
Converting Arrays and Custom Objects to Strings
77
3
Variables, Functions, and Flow Control
80
22
Creating a JavaScript Variable
80
4
Creating a Named Function
84
3
Nesting Named Functions
87
2
Creating an Anonymous Function
89
1
Delaying a Function Call
90
2
Branching Execution Based on Conditions
92
4
Handling Script Errors Gracefully
96
2
Improving Script Performance
98
4
Browser Feature Detection
102
23
Detecting the Browser Brand
108
1
Detecting an Early Browser Version
109
1
Detecting the Internet Explorer Version
110
1
Detecting the Netscape Navigator Version
111
2
Detecting the Client Operating System
113
1
Detecting Object Support
114
3
Detecting Object Property and Method Support
117
2
Detecting the Browser Written Language
119
1
Detecting Cookie Availability
120
1
Defining Browser- or Feature-Specific Links
121
2
Testing on Multiple Browser Versions
123
2
Managing Browser Windows
125
41
Setting the Main Window's Size
127
2
Positioning the Main Window
129
1
Maximizing the Main Window
130
2
Creating a New Window
132
3
Bringing a Window to the Front
135
1
Communicating with a New Window
136
3
Communicating Back to the Main Window
139
1
Using Internet Explorer Modal/Modeless Windows
140
3
Simulating a Cross-Browser Modal Dialog Window
143
7
Simulating a Window with Layers
150
16
Managing Multiple Frames
166
22
Creating a Blank Frame in a New Frameset
171
2
Changing the Content of One Frame from Another
173
1
Changing the Content of Multiple Frames at Once
174
2
Replacing a Frameset with a Single Page
176
1
Avoiding Being ``Framed'' by Another Site
176
2
Assuring a Page Loads in its Frameset
178
2
Reading a Frame's Dimensions
180
2
Setting Frameset Specifications Dynamically
185
3
Auto-Focusing the First Text Field
191
1
Performing Common Text Field Validations
192
5
Preventing Form Submission upon Validation Failure
197
3
Auto-Focusing an Invalid Text Field Entry
200
2
Changing a Form's Action
202
1
Blocking Submissions from the Enter Key
203
1
Advancing Text Field Focus with the Enter Key
204
1
Submitting a Form by an Enter Key Press in Any Text Box
205
2
Disabling Form Controls
207
1
Hiding and Showing Form Controls
208
3
Allowing Only Numbers (or Letters) in a Text Box
211
2
Auto- Tabbing for Fixed-Length Text Boxes
213
1
Changing select Element Content
214
4
Copying Form Data Between Pages
218
4
Equalizing the IE and W3C Event Models
227
2
Initiating a Process After the Page Loads
229
2
Determining the Coordinates of a Click Event
231
4
Preventing an Event from Performing Its Default Behavior
235
3
Blocking Double Clicks
238
1
Determining Which Element Received an Event
239
2
Determining Which Mouse Button Was Pressed
241
2
Reading Which Character Key Was Typed
243
2
Reading Which Noncharacter Key Was Pressed
245
3
Determining Which Modifier Keys Were Pressed During an Event
248
2
Determining the Element the Cursor Rolled From/To
250
4
Synchronizing Sounds to Events
254
2
Page Navigation Techniques
256
62
Loading a New Page or Anchor
259
2
Keeping a Page Out of the Browser History
261
1
Using a select Element for Navigation
262
2
Passing Data Between Pages Via Cookies
264
2
Passing Data Between Pages Via Frames
266
2
Passing Data Between Pages Via URLs
268
3
Creating a Contextual (Right-Click) Menu
271
8
Creating Drop-Down Navigation Menus
279
13
Providing Navigation Trail Menus
292
4
Creating Expandable Menus
296
11
Creating Collapsible XML Menus
307
11
Managing Style Sheets
318
19
Assigning Style Sheet Rules to an Element Globally
320
2
Assigning Style Sheet Rules to a Subgroup of Elements
322
1
Assigning Style Sheet Rules to an Individual Element
323
1
Importing External Style Sheets
324
1
Importing Browser- or Operating System--Specific Style Sheets
325
1
Changing Imported Style Sheets After Loading
326
2
Enabling/Disabling Style Sheets
328
1
Toggling Between Style Sheets for an Element
329
1
Overriding a Style Sheet Rule
330
1
Turning Arbitrary Content into a Styled Element
331
1
Creating Center-Aligned Body Elements
332
1
Reading Effective Style Sheet Property Values
333
2
Forcing Version 6 Browsers into Standards-Compatibility Mode
335
2
Visual Effects for Stationary Content
337
26
Swapping Images (Rollovers)
342
3
Changing Text Style Properties
345
2
Offering Body Text Size Choices to Users
347
4
Creating Custom Link Styles
351
2
Changing Page Background Colors and Images
353
2
Hiding and Showing Elements
355
2
Adjusting Element Transparency
357
1
Creating Transition Visual Effects
358
5
Positioning HTML Elements
363
54
Making an Element Positionable in the Document Space
368
1
Connecting a Positioned Element to a Body Element
369
2
Controlling Positioning Via a DHTML JavaScript Library
371
6
Deciding Between div and span Containers
377
2
Adjusting Positioned Element Stacking Order (z-order)
379
2
Centering an Element on Top of Another Element
381
2
Centering an Element in a Window or Frame
383
3
Determining the Location of a Nonpositioned Element
386
1
Animating Straight-Line Element Paths
387
4
Animating Circular Element Paths
391
2
Creating a Draggable Element
393
5
Scrolling div Content
398
6
Creating a Custom Scrollbar
404
13
Creating Dynamic Content
417
42
Writing Dynamic Content During Page Loading
418
1
Creating New Page Content Dynamically
419
2
Including External HTML Content
421
3
Embedding Data as JavaScript Objects
427
2
Transforming XML Data into HTML Tables
429
3
Transforming JavaScript Objects into HTML Tables
432
2
Converting an XML Node Tree to JavaScript Objects
434
2
Creating a New Element
436
2
Creating Text Content for a New Element
438
2
Creating Mixed Element and Text Nodes
440
2
Inserting and Populating an iframe Element
442
2
Getting a Reference to an HTML Element Object
444
2
Replacing Portions of Body Content
446
1
Removing Body Content
447
2
Sorting Dynamic Tables
449
3
Walking the Document Node Tree
452
5
Capturing Document Content
457
2
Dynamic Content Applications
459
40
Displaying a Random Aphorism
460
2
Converting a User Selection into an Arbitrary Element
462
2
Automating the Search-and-Replace of Body Content
464
3
Creating a Slide Show
467
8
Auto-Scrolling the Page
475
1
Greeting Users with Their Time of Day
476
1
Displaying the Number of Days Before Christmas
477
2
Displaying a Countdown Timer
479
7
Creating a Calendar Date Picker
486
8
Displaying an Animated Progress Bar
494
5
A. Keyboard Event Character Values
499
2
B. Keyboard Key Code Values
501
2
C. ECMAScript Reserved Keywords
503
2