Preface

Return to home page.
JavaScript is a simple and popular language to handle the Web. You can use it to learn elementary computer programming concepts and techniques. If you get good at it, you can use it to make the Web do lots of fancy and useful things.

This little book is intended for three types of people:

You need no knowledge of HTML or computer programming to use this book. The book will introduce you to both.

But if you have knowledge of one or both of these subjects, your job will become easier. Those who already know HTML can concentrate on programming. Those who already know programming can concentrate on the syntax of JavaScript and how to use it to manipulate HTML.

What tools do you need to break into this field? A text editor and a Web browser. In this book, we use Notepad, which comes with Windows; you can use any editor you want. The browser can be Netscape Navigator 2 or later or Internet Explorer 3 or later. If you use one of the 4.0 or later browsers, you can take advantage of more features. These browsers either come with new computers or can be downloaded from the Internet.

This book covers most of the JavaScript topics. It gives you lots of breadth but little depth. You get a taste of what these features can do. If you want more depth, you are welcome to try The JavaScript Coursebook by this author.

This book has four chapters. Each comes with 10 Drill and 10 Practice questions at the end. The former drill you on some simple terms and concepts. The latter require you to do something. The answers appear after the questions.

This site also stores the lengthier source files listed in the book. If a listing in the text starts with a file name, that file is available here. You can run the file to see the result on your screen. If you wish, you can download it to your local drive. That may save you the trouble of typing.


Table of Contents

Return to home page.

Preface   vii

1   JavaScript Basics   1
A.   JavaScript Overview   1
B.   Using a Text Editor   2
C.   HTML Basics   3
D.   Static and Dynamic Pages   7
E.   Object Concepts and Terms   9
F.   JavaScript Basic Structure   10
G.   Dialog Boxes   12
H.   Handling Events   14
I.   Functions   17
     a.   Function Basics   17
     b.   Passing Arguments   18
     c.   Returning Values   22
J.   Loading Sequence and Script Placing   22
K.   Importing Scripts   24

2   Programming Basics   33
A.   Variables and Scope   33
B.   Operators and Precedence   36
     a.   Arithmetic Operators   36
     b.   Assignment Operators   36
     c.   Comparison and Logical Operators   38
C.   Branching with if   40
D.   Branching with switch   41
E.   Looping with for   44
F.   Looping with while   50
G.   Escape Sequences   52

3   DOM and Form   61
A.   Document Object Model   61
B.   Forms and Controls   62
C.   Referencing Elements   63
D.   Events and Naming Conventions   67
E.   Push Buttons   69
F.   Text Boxes   72
     a.   One-Line Box   72
     b.   Textarea Box   76
G.   Radio Buttons   78
H.   Checkboxes   81
I.   Select Boxes   83

4   Fun Stuff   95
A.   The window Object   95
B.   The document Object   97
C.   Opening New Windows   98
D.   Opening New Pages   100
E.   Tracking Object Members   102
F.   Colors   103
G.   Tables   105
H.   Arrays   108
I.   Point and Click Calculator   113
J.   Date and Time Manipulation   115
     a.   Timer   115
     b.   Scrolling Text   117
     c.   The Date Object   119
     d.   Digital Clock   121

Index   131
1