1 Introduction To Javascript - . - . - . - . - . - . - . - . - . - . - . - . - . - . - . - . - . - . .

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Color profile: Generic CMYK printer profile Begin8 / JavaScript: A Beginner’s Guide / Pollock / 3140-3 / 1

Composite Default screen


Blind Folio FM:v

Contents
ACKNOWLEDGMENTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
INTRODUCTION. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
1 Introduction to JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
What You Need to Know . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Basic HTML Knowledge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Basic Text Editor and Web Browser Knowledge . . . . . . . . . . . . . . . . 3
Which Version? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Remember, It’s Not Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Similarities to Other Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Introduction to JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Object Based . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Client Side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Scripting Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Putting It All Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Online Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Project 1-1: Using JavaScript to Write Text . . . . . . . . . . . . . . . . . . . . . . . . . 12
Mastery Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2 Placing JavaScript in an HTML File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Using the HTML SCRIPT Tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Identifying the Scripting Language . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Calling External Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Hiding JavaScript Code from Older Browsers . . . . . . . . . . . . . . . . . . 18
Creating Your First Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Writing a “Hello World” Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Creating an HTML Document for the Script . . . . . . . . . . . . . . . . . . 21
Inserting the Script into the HTML Document . . . . . . . . . . . . . . . . . 21
Project 2-1: Insert a Script into an HTML Document . . . . . . . . . . . . . . . . . . 24
Revisiting “Hello World” in External Form . . . . . . . . . . . . . . . . . . . . . . . . . 26
Creating a JavaScript File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Creating the HTML Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Viewing the Pages in Your Browser . . . . . . . . . . . . . . . . . . . . . . . . . 28
Project 2-2: Call an External Script from an HTML Document . . . . . . . . . . 29
Using JavaScript Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Inserting Comments on One Line . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Adding Multiple-Line Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Mastery Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

P:\010Comp\Begin8\140-3\fm.vp
Friday, March 09, 2001 2:00:40 PM
Color profile: Generic CMYK printer profile Begin8 / JavaScript: A Beginner’s Guide / Pollock / 3140-3 / Front Matter
Composite Default screen
Blind Folio FM:vi

vi JavaScript: A Beginner’s Guide

3 Using Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
What Is a Variable? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Why Are Variables Useful? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Variables as Time-Savers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Variables as Code Clarifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Defining Variables for Your Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Declaring Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Assigning Values to Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Naming Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Understanding Variable Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Boolean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Null . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Project 3-1: Declare Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Using Variables in Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Making a Call to a Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Adding Variables to Text Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Writing a Page of JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Creating the Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Defining the Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Adding the Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Modifying the Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Project 3-2: Create an HTML Page with JavaScript . . . . . . . . . . . . . . . . . . . 64
Mastery Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
4 Using Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
What Is a Function? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Why Are Functions Useful? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Structuring Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Declaring Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Defining the Code for Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Naming Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Adding Parameters to Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Adding Return Statements to Functions . . . . . . . . . . . . . . . . . . . . . . 78
Calling Functions in Your Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Calling a Function in the HEAD Section . . . . . . . . . . . . . . . . . . . . . 80
Calling a Function in the BODY Section . . . . . . . . . . . . . . . . . . . . . 84
Calling a Function from Another Function . . . . . . . . . . . . . . . . . . . . 87
Calling Functions with Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Calling Functions with Return Statements . . . . . . . . . . . . . . . . . . . . 94
Project 4-1: Create an HTML Page with Functions . . . . . . . . . . . . . . . . . . . 97
Putting It All Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

P:\010Comp\Begin8\140-3\fm.vp
Friday, March 09, 2001 2:00:40 PM
Color profile: Generic CMYK printer profile Begin8 / JavaScript: A Beginner’s Guide / Pollock / 3140-3 / Front Matter
Composite Default screen
Blind Folio FM:vii

Contents vii

Project 4-2: Write Your Own Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 102


Mastery Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
5 JavaScript Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Understanding the Operator Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Mathematical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
The Addition Operator (+) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
The Subtraction Operator (–) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
The Multiplication Operator (*) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
The Division Operator (/) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
The Modulus Operator (%) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
The Increment Operator (++) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
The Decrement Operator (– –) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
The Unary Negation Operator (–) . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Assignment Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
The Assignment Operator (=) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
The Add-and-Assign Operator (+=) . . . . . . . . . . . . . . . . . . . . . . . . . 119
The Subtract-and-Assign Operator (–=) . . . . . . . . . . . . . . . . . . . . . . 120
The Multiply-and-Assign Operator (*=) . . . . . . . . . . . . . . . . . . . . . . 121
The Divide-and-Assign Operator (/=) . . . . . . . . . . . . . . . . . . . . . . . 121
The Modulus-and-Assign Operator (%=) . . . . . . . . . . . . . . . . . . . . . 122
Project 5-1: Adjust a Variable Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Comparison Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
The Is-Equal-To Operator (==) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
The Is-Not-Equal-To Operator (!=) . . . . . . . . . . . . . . . . . . . . . . . . . 127
The Is-Greater-Than Operator (>) . . . . . . . . . . . . . . . . . . . . . . . . . . 127
The Is-Less-Than Operator (<) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
The Is-Greater-Than-or-Equal-To Operator (>=) . . . . . . . . . . . . . . 129
The Is-Less-Than-or-Equal-To Operator (<=) . . . . . . . . . . . . . . . . . 130
Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
The AND Operator (&&) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
The OR Operator (||) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
The NOT Operator (!) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
The Bitwise Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Order of Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Project 5-2: True or False? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Mastery Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
6 Conditional Statements and Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Defining Conditional Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
What Is a Conditional Statement? . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Why Conditionals Are Useful . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
Conditional Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Using If/Else Statement Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142

P:\010Comp\Begin8\140-3\fm.vp
Friday, March 09, 2001 2:00:40 PM
Color profile: Generic CMYK printer profile Begin8 / JavaScript: A Beginner’s Guide / Pollock / 3140-3 / Front Matter
Composite Default screen
Blind Folio FM:viii

viii JavaScript: A Beginner’s Guide

Using the switch Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152


Project 6-1: Construct an if/else block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
Defining Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
What Is a Loop? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
Why Loops Are Useful . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
for . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
do while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Project 6-2: Work with for loops and while loops . . . . . . . . . . . . . . . . . . . . 172
Mastery Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
7 Event Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
What Is an Event Handler? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Why Event Handlers Are Useful . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Event Handler Locations and Uses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
Event Handler Locations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
Using Event Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Project 7-1: Create a Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
The Event Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
The Click Event (onClick) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
The Mouseover Event (onMouseOver) . . . . . . . . . . . . . . . . . . . . . . 185
The Mouseout Event (onMouseout) . . . . . . . . . . . . . . . . . . . . . . . . . 187
The Load Event (onLoad) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
The Unload Event (onUnload) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
The Focus Event (onFocus) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
The Blur Event (onBlur) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
The Change Event (onChange) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
The Submit Event (onSubmit) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
Project 7-2: Use Events to Send Out Alerts . . . . . . . . . . . . . . . . . . . . . . . . . 195
More Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
The Abort Event (onAbort) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
The Dragdrop Event (onDragDrop) . . . . . . . . . . . . . . . . . . . . . . . . . 196
The Error Event (onError) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
The Keydown Event (onKeyDown) . . . . . . . . . . . . . . . . . . . . . . . . . 197
The Keypress Event (onKeyPress) . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
The Keyup Event (onKeyUp) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
The Mousedown Event (onMouseDown) . . . . . . . . . . . . . . . . . . . . . 198
The Mouseup Event (onMouseUp) . . . . . . . . . . . . . . . . . . . . . . . . . 198
The Mousemove Event (onMouseMove) . . . . . . . . . . . . . . . . . . . . . 198
The Move Event (onMove) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
The Reset Event (onReset) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
The Resize Event (onResize) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
The Select Event (onSelect) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199

P:\010Comp\Begin8\140-3\fm.vp
Friday, March 09, 2001 2:00:41 PM
Color profile: Generic CMYK printer profile Begin8 / JavaScript: A Beginner’s Guide / Pollock / 3140-3 / Front Matter
Composite Default screen
Blind Folio FM:ix

Contents ix

Scripts for Event Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199


The Status Bar Change . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
The Button Link . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Project 7-3: Practicing with Window Status and Location Properties . . . . . . . 205
Mastery Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
8 Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
Defining Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
What Is an Object? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
Why Objects Are Useful . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Creating Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Naming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Object Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
Adding Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Project 8-1: Create a Computer Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
Predefined JavaScript Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
The Navigator Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Project 8-2: Practicing with the Predefined Navigator Object . . . . . . . . . . . . 236
Mastery Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
9 The Document Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
An Introduction to the Document Object . . . . . . . . . . . . . . . . . . . . . . . . . . 240
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
The alinkColor Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
The anchors Property (Array) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
The applets Property (Array) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
The bgColor Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
The cookie Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
The domain Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
The embeds Property (Array) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
The fgColor Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
The formName Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
The forms Property (Array) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
The images Property (Array) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
The lastModified Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
The layers Property (Array) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
The all Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
The linkColor Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
The links Property (Array) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
The plugins Property (Array) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
The referrer Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
The title Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
The URL Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
The vlinkColor Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267

P:\010Comp\Begin8\140-3\fm.vp
Friday, March 09, 2001 2:00:41 PM
Color profile: Generic CMYK printer profile Begin8 / JavaScript: A Beginner’s Guide / Pollock / 3140-3 / Front Matter
Composite Default screen
Blind Folio FM:x

x JavaScript: A Beginner’s Guide

Project 9-1: Using Properties to Create a Page . . . . . . . . . . . . . . . . . . . . . . . 269


Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
The open() and close() Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
The write() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
The writeln() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Project 9-2: Extending te Basic Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
Mastery Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
10 Window Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
An Introduction to the Window Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
The closed Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
The defaultStatus Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
The frames Property (Array) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
The length Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
The location Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
The name Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
The opener Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
The parent Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
The self Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
The status Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
The top Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
Project 10-1: Using the Location Property of the Window Object . . . . . . . . 289
Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
The alert() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
The confirm() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
The find() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
The print() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
The prompt() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
The open() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
The close() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
The blur() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
The focus() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
The moveBy() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
The moveTo() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
The resizeBy() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
The resizeTo() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
The scrollBy() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
The scrollTo() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
The setInterval() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
The clearInterval() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
The setTimeout() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
The clearTimeout() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
Project 10-2: Create a New Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
Mastery Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319

P:\010Comp\Begin8\140-3\fm.vp
Friday, March 09, 2001 2:00:41 PM
Color profile: Generic CMYK printer profile Begin8 / JavaScript: A Beginner’s Guide / Pollock / 3140-3 / Front Matter
Composite Default screen
Blind Folio FM:xi

Contents xi

11 JavaScript Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321


What Is an Array? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322
Why Arrays Are Useful . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
Defining and Accessing Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
Naming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
Defining an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
Accessing an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
Other Ways to Define Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
Array Object Properties and Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
Arrays and Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
Creating Array Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
Moving Through Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
Project 11-1: Using Loops with Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
Associative Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
Defining Associative Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
Accessing Associative Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
Project 11-2: Using Associative Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
Mastery Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
12 Math and Date Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361
The Math Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362
What Is the Math Object? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362
How the Math Object Is Useful . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363
The E Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
The LN10 Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
The LN2 Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
The LOG10E Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
The LOG2E Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
The PI Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
The SQRT2 Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
The SQRT1_2 Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
The Basic Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
The Two-Parameter Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
The Other Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
The random() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
Project 12-1: Displaying a Random Link on a Page . . . . . . . . . . . . . . . . . . . . . 385
The Date Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386
Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
Methods That Get Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389

P:\010Comp\Begin8\140-3\fm.vp
Friday, March 09, 2001 2:00:41 PM
Color profile: Generic CMYK printer profile Begin8 / JavaScript: A Beginner’s Guide / Pollock / 3140-3 / Front Matter
Composite Default screen
Blind Folio FM:xii

xii JavaScript: A Beginner’s Guide

Methods That Set Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392


Other Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393
How About Some Date Scripts? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
Project 12-2: Creating a JavaScript Clock . . . . . . . . . . . . . . . . . . . . . . . . . . . 397
Mastery Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
13 Handling Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
Introduction to the string Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402
The string Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402
The String Literal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403
What’s the Difference? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403
Properties of the string Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
The constructor Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
The length Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406
The prototype Property . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407
Methods of the string Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408
The anchor() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409
The big() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410
The blink() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410
The bold() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
The charAt() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
The charCodeAt() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414
The concat() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414
The fixed() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
The fontcolor() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416
The fontsize() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
The fromCharCode() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
The indexOf() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
The italics() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420
The lastIndexOf() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420
The link() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421
The match() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422
The replace() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
The search() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
The slice() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
The small() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
The split() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
The strike() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426
The sub() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426
The substr() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
The substring() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
The sup() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
The toString() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428

P:\010Comp\Begin8\140-3\fm.vp
Friday, March 09, 2001 2:00:42 PM
Color profile: Generic CMYK printer profile Begin8 / JavaScript: A Beginner’s Guide / Pollock / 3140-3 / Front Matter
Composite Default screen
Blind Folio FM:xiii

Contents xiii

The toLowerCase() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428


The toUpperCase() Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
Project 13-1: Use charAt() to Find a First Letter . . . . . . . . . . . . . . . . . . . . . . 430
Putting It All Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
Project 13-2: Use indexOf() to Test an Address . . . . . . . . . . . . . . . . . . . . . . 434
Mastery Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435
14 JavaScript and Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437
Accessing a Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438
Using the forms Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438
Using Form Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
Properties and Methods of the form Object . . . . . . . . . . . . . . . . . . . . . . . . . 445
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459
Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460
onSubmit and the return Statement . . . . . . . . . . . . . . . . . . . . . . . . . 460
Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462
Project 14-1: What’s the Time? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465
Forms for Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466
Select Box Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466
Radio Button Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470
Project 14-2: Select Box Navigation Script . . . . . . . . . . . . . . . . . . . . . . . . . . 471
Mastery Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472
15 JavaScript and Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475
An Introduction to Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476
Purpose of Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476
The Code Behind the Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477
Frame Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479
Accessing Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
The frames Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484
Using a Frame Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487
Changing Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489
Change a Single Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490
Change Multiple Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
Project 15-1: Frame Changing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494
Frame Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495
Using the Select Box with Frames . . . . . . . . . . . . . . . . . . . . . . . . . . 496
Breaking Out of Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
Sending Viewers to Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500
Using Variables Across Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 502
Project 15-2: Variables Again . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507
Mastery Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507

P:\010Comp\Begin8\140-3\fm.vp
Friday, March 09, 2001 2:00:42 PM
Color profile: Generic CMYK printer profile Begin8 / JavaScript: A Beginner’s Guide / Pollock / 3140-3 / Front Matter
Composite Default screen
Blind Folio FM:xiv

xiv JavaScript: A Beginner’s Guide

16 An Introduction to Advanced Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . 509


XML and XHTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 510
How XML Affects Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 510
Where to Learn More About XML and XHTML . . . . . . . . . . . . . . . 514
Debugging Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515
Types of Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515
Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523
Creating Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523
Testing Strings Against Regular Expressions . . . . . . . . . . . . . . . . . . . 524
Adding Flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526
Creating Powerful Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527
Replacing Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532
Project 16-1: Validating a Web Address . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534
Cookies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535
Setting a Cookie . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536
Reading a Cookie . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
Project 16-2: Remember a Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542
Mastery Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543
17 More Advanced Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545
Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546
Preloading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546
Rollovers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548
Project 17-1: Create a Navigational System of Images . . . . . . . . . . . . . . . . . . 562
DHTML Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563
Cascading Style Sheets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563
Moving Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568
Animating Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571
JavaScript Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573
Security and Signed Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573
Page Protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 574
Project 17-2: Use DHTML Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576
Mastery Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576
A Answers to Mastery Checks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579
Module 1: Introduction to JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580
Module 2: Placing JavaScript in an HTML File . . . . . . . . . . . . . . . . . . . . . . 580
Module 3: Using Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580
Module 4: Using Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 581
Module 5: JavaScript Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 581
Module 6: Conditional Statements and Loops . . . . . . . . . . . . . . . . . . . . . . . . 581
Module 7: Event Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582
Module 8: Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582
Module 9: The Document Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583

P:\010Comp\Begin8\140-3\fm.vp
Friday, March 09, 2001 2:00:42 PM
Color profile: Generic CMYK printer profile Begin8 / JavaScript: A Beginner’s Guide / Pollock / 3140-3 / Front Matter
Composite Default screen
Blind Folio FM:xv

Contents xv

Module 10: Window Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583


Module 11: Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 584
Module 12: Math and Date Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 584
Module 13: Handling Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 584
Module 14: JavaScript and Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585
Module 15: JavaScript and Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585
Module 16: An Introduction to Advanced Techniques . . . . . . . . . . . . . . . . . 586
Module 17: More Advanced Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . 586

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 587

P:\010Comp\Begin8\140-3\fm.vp
Friday, March 09, 2001 2:00:42 PM

You might also like