Brooks, David R., An Introduction to HTML/JavaScript for Scientists and Engineers

From the introduction...

There are many students, other than those specifically interested in computer-related areas such as computer science or computer engineering, who need to know how to solve computational problems on computers. There are basically two approaches to meeting the needs of such students. One is to rely on software packages such as spreadsheets, using built-in functions, with or without using explicitly any of the constructs, such as branching and looping, that are common to programming languages.

A second approach is to teach such students a traditional programming language, previously Fortran or Pascal, and more recently C, C++, or Java. These languages play important roles in certain kinds of work, such as computer science (C++, Java) or scientific computing (Fortran), but having to learn one of them may be viewed, possibly with good reason, as irrelevant by many students.

From a student’s point of view, there is no painless solution to this dilemma, but in this book I suggest that learning to solve computational problems in an HTML/JavaScript environment will at least appear to be a more relevant solution. Both HTML and JavaScript are essential for Web development and some working knowledge of them is a useful and marketable skill. So, in addition to learning basic programming concepts, students can also learn something that may be more immediately valuable than older text-based languages.

In many ways, the HTML/JavaScript environment is more difficult to learn than a traditional text-based programming language. C, for example, is a mature, fairly small language with an unambiguous set of syntax rules and relatively primitive input/output interface capabilities. Programs written in ANSI Standard C should work equally well on any computing platform that has a C compiler, making the language inherently platform-independent. The limitations of C can be viewed as either a blessing or a curse, depending on the application.

JavaScript and HTML, on the other hand, are immature and very unstable languages (if we can agree to call HTML a language) that function within a constantly changing Web environment. There are dialects of both HTML and JavaScript that will work only on particular computing platforms. While it is true that there are extensions to languages such as C that are platform-dependent, the platform dependence of HTML and JavaScript is a major implementation issue rather than an occasionally minor inconvenience.

As one indication of the teaching and learning challenge these environments provide, just two popular paperback HTML and JavaScript reference books occupy nearly 6 inches of space on my office bookshelf! A great deal of the material in those books is devoted to explaining the differences among various versions of HTML and JavaScript.

Nonetheless, it is possible to present some core subsets of both HTML and JavaScript that will allow students to solve some of the same kinds of computational problems that would be appropriate for a more traditional language such as C or C++. So, I have concluded that it is reasonable to present some basic programming skills in the context of an HTML/JavaScript environment.

Contents

Chapter One: Introductory Concepts
1.1 Introduction
          1.1.1 What is the purpose of this book?
          1.1.2 Learning by Example
1.2 Introducing the Tools
          1.2.1 What is an HTML document?
          1.2.2 What is JavaScript?
          1.2.3 How Do You Create HTML/JavaScript Documents?
          1.2.4 Some Typographic Conventions Used in This Book
          1.2.5 Where Should I Look for More Information About HTML and JavaScript?
1.3 Your First JavaScript Script
1.4 Another Example

Chapter Two: HTML Document Basics
2.1 Documents, Elements, Attributes, and Values
          2.1.1 Essential Elements
          2.1.2 Some Other Important Elements
2.2 HTML Syntax and Style
2.3 Using the script Element
2.4 Creating and Organizing a Web Site
2.5 Selecting Colors
2.6 Using Cascading Style Sheets
2.7 Another Example

Chapter Three: HTML Tables, Forms, and Lists
3.1 The table Element
          3.1.1 Basic table Formatting
          3.1.2 Merging Cells Across Rows and Columns
3.2 The form Element
3.3 Creating Pull-Down Menus
3.4 Combining Tables and Forms
3.5 E-Mailing the Contents of Forms
3.6 The list Element
3.7 Another Example

Chapter Four: Fundamentals of the JavaScript Language
4.1 Capabilities of JavaScript
4.2 Some Essential Terminology
4.3 Structure of JavaScript Code
          4.3.1 JavaScript Statements
          4.3.2 Statement Blocks
          4.3.3 Comments
4.4 Data and Objects
          4.4.1 Data Declarations and Variables
          4.4.2 Data Types
          4.4.3 Literals
          4.4.4 Case Sensitivity
          4.4.5 A First Look at Objects and Methods
          4.4.6 String Methods
4.5 Tokens, Operators, Expressions, and Statements
          4.5.1 Tokens
          4.5.2 Arithmetic Operators
          4.5.3 The Assignment Operator
          4.5.4 Shorthand Arithmetic/Assignment Operators
4.6 The JavaScript Math Object
4.7 Comparison Operators and Decision-Making (Branching) Structures
          4.7.1 Relational and Logical Operators
          4.7.2 The if... Construct (Branching Structures)
          4.7.3 The switch construct
4.8 Loop Structures
          4.8.1 Count-Controlled Loops
          4.8.2 Conditional Loops
4.9 Using JavaScript to Change Values in Form Fields
4.10 Arrays
          4.10.1 Basic Array Properties
          4.10.2 Some Operations on Arrays
          4.10.3 Simulating Multidimensional Arrays
          4.10.4 Using Arrays for Data Manipulation
          4.10.5 Using Arrays to Access the Contents of Forms
4.11 Hiding the Contents of a JavaScript Script
4.12 Accessing the Choices made in Check Boxes, Radio Buttons, and Pull-Down Lists
4.13 More Examples

Chapter Five: JavaScript Functions
5.1 The Purpose of Functions in Programming
5.2 Defining JavaScript Functions
5.3 Using JavaScript Functions with HTML Forms
          5.3.1 Using Numerical Values as Input
          5.3.2 Using Field Names as Input
          5.3.3 Using Entire Forms as Input
5.4 Some Global Methods and Event Handlers
          5.4.1 Global Methods
          5.4.2 Using Event Handlers with Forms and Functions
5.5 Recursive Functions
5.6 Passing Values From One Document to Another
5.7 Revisiting the JavaScript sort() Method
5.8 More Examples

Glossary
Appendix: Displaying Special Characters in an HTML Document
Exercises