CITATION

Pollock, John. JavaScript, A Beginner's Guide, Third Edition. US: McGraw-Hill Osborne Media, 2009.

JavaScript, A Beginner's Guide, Third Edition

Authors:

Published:  September 2009

eISBN: 9780071632966 0071632964 | ISBN: 9780071632959
  • Contents
  • Acknowledgments
  • Introduction
  • 1 Introduction to JavaScript
  • What You Need to Know
  • Basic HTML and CSS Knowledge
  • Basic Text Editor and Web Browser Knowledge
  • Which Version?
  • Remember, It’s Not Java
  • Similarities to Other Languages
  • Beginning with JavaScript
  • Object Based
  • Client Side
  • Scripting Language
  • Putting It All Together
  • Online Resources
  • Try This 1-1: Use JavaScript to Write Text
  • 2 Placing JavaScript in an HTML File
  • Using the HTML Script Tags
  • Identifying the Scripting Language
  • Calling External Scripts
  • Using <noscript></noscript> Tags
  • Creating Your First Script
  • Writing a “Hello World” Script
  • Creating an HTML Document for the Script
  • Inserting the Script into the HTML Document
  • Try This 2-1: Insert a Script into an HTML Document
  • Using External JavaScript Files
  • Creating a JavaScript File
  • Creating the HTML Files
  • Viewing the Pages in Your Browser
  • Try This 2-2: Call an External Script from an HTML Document
  • Using JavaScript Comments
  • Inserting Comments on One Line
  • Adding Multiple-Line Comments
  • 3 Using Variables
  • Understanding Variables
  • Why Variables Are Useful
  • Variables as Placeholders for Unknown Values
  • Variables as Time-Savers
  • Variables as Code Clarifiers
  • Defining Variables for Your Scripts
  • Declaring Variables
  • Assigning Values to Variables
  • Naming Variables
  • Understanding Variable Types
  • Number
  • String
  • Boolean
  • Null
  • Try This 3-1: Declare Variables
  • Using Variables in Scripts
  • Making a Call to a Variable
  • Adding Variables to Text Strings
  • Writing a Page of JavaScript
  • Creating the Framework
  • Defining the Variables
  • Adding the Commands
  • Modifying the Page
  • Try This 3-2: Create an HTML Page with JavaScript
  • 4 Using Functions
  • What a Function Is
  • Why Functions Are Useful
  • Structuring Functions
  • Declaring Functions
  • Defining the Code for Functions
  • Naming Functions
  • Adding Parameters to Functions
  • Adding Return Statements to Functions
  • Calling Functions in Your Scripts
  • Script Tags: Head Section or Body Section
  • Calling a Function from Another Function
  • Calling Functions with Parameters
  • Calling Functions with Return Statements
  • Other Ways to Define Functions
  • Try This 4-1: Create an HTML Page with Functions
  • Putting It All Together
  • Try This 4-2: Write Your Own Functions
  • 5 JavaScript Operators
  • Understanding the Operator Types
  • Understanding Mathematical Operators
  • The Addition Operator (+)
  • The Subtraction Operator (–)
  • The Multiplication Operator (*)
  • The Division Operator (/)
  • The Modulus Operator (%)
  • The Increment Operator (++)
  • The Decrement Operator (– –)
  • The Unary Negation Operator (–)
  • Understanding Assignment Operators
  • The Assignment Operator (=)
  • The Add-and-Assign Operator (+=)
  • The Subtract-and-Assign Operator (–=)
  • The Multiply-and-Assign Operator (*=)
  • The Divide-and-Assign Operator (/=)
  • The Modulus-and-Assign Operator (%=)
  • Try This 5-1: Adjust a Variable Value
  • Understanding Comparison Operators
  • The Is-Equal-To Operator (==)
  • The Is-Not-Equal-To Operator (!=)
  • The Is-Greater-Than Operator (>)
  • The Is-Less-Than Operator (<)
  • The Is-Greater-Than-or-Equal-To Operator (>=)
  • The Is-Less-Than-or-Equal-To Operator (<=)
  • The Strict Is-Equal-To Operator (===)
  • The Strict Is-Not-Equal-To Operator (!==)
  • Understanding Logical Operators
  • The AND Operator (&&)
  • The OR Operator (||)
  • The NOT Operator (!)
  • The Bitwise Operators
  • Special Operators
  • Understanding Order of Operations
  • Try This 5-2: True or False?
  • 6 Conditional Statements and Loops
  • Defining Conditional Statements
  • What Is a Conditional Statement?
  • Why Conditional Statements Are Useful
  • Using Conditional Statements
  • Using if/else Statement Blocks
  • Using the switch Statement
  • Using the Conditional Operator
  • Try This 6-1: Construct an if/else Block
  • Defining Loops
  • What Is a Loop?
  • Why Loops Are Useful
  • Using Loops
  • for
  • while
  • do while
  • for in
  • for each in
  • Using break and continue
  • Try This 6-2: Work with for Loops and while Loops
  • 7 Event Handlers
  • What Is an Event Handler?
  • Why Event Handlers Are Useful
  • Understanding Event Handler Locations and Uses
  • Using an Event Handler in an HTML Element
  • Using an Event Handler in the Script Code
  • Try This 7-1: Create a Button
  • Learning the Event Handlers
  • The Abort Event (onabort)
  • The Blur Event (onblur)
  • The Change Event (onchange)
  • The Click Event (onclick)
  • The Focus Event (onfocus)
  • The Keydown Event (onkeydown)
  • The Keypress Event (onkeypress)
  • The Keyup Event (onkeyup)
  • The Load Event (onload)
  • The Mousedown Event (onmousedown)
  • The Mousemove Event (onmousemove)
  • The Mouseover Event (onmouseover)
  • The Mouseout Event (onmouseout)
  • The Mouseup Event (onmouseup)
  • The Reset Event (onreset)
  • The Submit Event (onsubmit)
  • The Unload Event (onunload)
  • Try This 7-2: Use Events to Send Out Alerts
  • Creating Scripts Using Event Handlers
  • The Text Box Message
  • The Button Link
  • Other Ways to Register Events
  • The addEventListener() Method
  • The attachEvent() Method
  • 8 Objects
  • Defining Objects
  • What Is an Object?
  • Why Objects Are Useful
  • Creating Objects
  • Naming
  • Object Structure
  • Adding Methods
  • Object Manipulation Statements
  • Try This 8-1: Create a Computer Object
  • Understanding Predefined JavaScript Objects
  • The Navigator Object
  • The History Object
  • Try This 8-2: Practice with the Predefined Navigator Object
  • 9 The Document Object
  • Defining the Document Object
  • Using the Document Object Model
  • Using the Properties of the Document Object
  • The Color Properties
  • The anchors Property (Array)
  • The cookie Property
  • The dir Property
  • The domain Property
  • The formname Property
  • The forms Property (Array)
  • The images Property (Array)
  • The lastModified Property
  • The layers Property (Array)
  • The all Property
  • The links Property (Array)
  • The referrer Property
  • The title Property
  • The URL Property
  • The URLUnencoded Property
  • Using the Methods of the Document Object
  • The getElementById() Method
  • The getElementsByClassName() Method
  • The getElementsByTagName() Method
  • The open() and close() Methods
  • The write() Method
  • The writeln() Method
  • Creation Methods
  • Try This 9-1: Add a DOM Node to the Document
  • Creating Dynamic Scripts
  • Styles in JavaScript
  • Coding a Dynamic Script
  • The innerHTML Property
  • Try This 9-2: Trying out Property Changes
  • 10 Window Object
  • An Introduction to the Window Object
  • Using the Properties of the Window Object
  • The closed Property
  • The defaultStatus Property
  • The frames Property (Array)
  • The innerHeight and innerWidth Properties
  • The length Property
  • The location Property
  • The name Property
  • The opener Property
  • The parent Property
  • The self Property
  • The status Property
  • The top Property
  • Try This 10-1: Use the location and innerWidth Properties
  • Using the Methods of the Window Object
  • The alert() Method
  • The confirm() Method
  • The find() Method
  • The home() Method
  • The print() Method
  • The prompt() Method
  • The open() Method
  • The close() Method
  • The moveBy() Method
  • The moveTo() Method
  • The resizeBy() Method
  • The resizeTo() Method
  • The scrollBy() Method
  • The scrollTo() Method
  • The setInterval() Method
  • The clearInterval() Method
  • The setTimeout() Method
  • The clearTimeout() Method
  • Try This 10-2: Use the setTimeout() and confirm() Methods
  • 11 JavaScript Arrays
  • What Is an Array?
  • Why Arrays Are Useful
  • Defining and Accessing Arrays
  • Naming an Array
  • Defining an Array
  • Accessing an Array’s Elements
  • Other Ways to Define Arrays
  • Understanding the Properties and Methods of the Array Object
  • Properties
  • Methods
  • Extended Array Methods
  • Using Arrays with Loops
  • Creating Array Elements
  • Moving Through Arrays
  • Try This 11-1: Use Loops with Arrays
  • Using Associative Arrays
  • Defining Associative Arrays
  • Accessing Associative Arrays
  • Try This 11-2: Use Associative Arrays
  • 12 Math, Number, and Date Objects
  • Using the Math Object
  • What Is the Math Object?
  • How the Math Object Is Useful
  • Properties
  • Methods
  • Try This 12-1: Display a Random Link on a Page
  • Understanding the Number Object
  • Properties
  • Methods
  • Using the Date Object
  • Properties
  • Methods
  • Methods That Get Values
  • Methods That Set Values
  • Other Methods
  • How About Some Date Scripts?
  • Try This 12-2: Create a JavaScript Clock
  • 13 Handling Strings
  • Introduction to the String Object
  • The String Object
  • The String Literal
  • What’s the Difference?
  • Using the Properties of the String Object
  • The constructor Property
  • The length Property
  • The prototype Property
  • Using the Methods of the String Object
  • Methods That Add HTML Tags
  • The Other Methods
  • Try This 13-1: Use charAt() to Find a First Letter
  • Putting Methods Together
  • Try This 13-2: Use indexOf() to Test an Address
  • Using Regular Expressions
  • Creating Regular Expressions
  • Testing Strings Against Regular Expressions
  • Adding Flags
  • Creating Powerful Patterns
  • Grouping Expressions
  • The replace(), match(), and search() Methods
  • More Information
  • 14 JavaScript and Forms
  • Accessing Forms
  • Using the forms Array
  • Using Form Names
  • Using an ID
  • Using the Properties and Methods of the Form Object
  • Properties
  • Methods
  • Ensuring the Accessibility of Forms
  • Using Proper Element and Label Order
  • Using <label></label> Tags
  • Using <fieldset></fieldset> Tags
  • Not Assuming Client-Side Scripting
  • Validation
  • onsubmit and the return Statement
  • Techniques
  • Try This 14-1: Request a Number
  • Using Forms for Navigation
  • Clicking a Button
  • Try This 14-2: Build a Select Box Navigation Script
  • 15 JavaScript and Frames
  • An Introduction to Frames
  • Purpose of Frames
  • The Code Behind the Frames
  • Frame Options
  • Accessing Frames
  • The frames Array
  • Using a Frame Name
  • Changing Frames
  • Change a Single Frame
  • Change Multiple Frames
  • Try This 15-1: Change Frames
  • Step by Step
  • Frame Navigation
  • Using the Select Box with Frames
  • Breaking Out of Frames
  • Sending Viewers to Frames
  • Using Variables Across Frames
  • Try This 15-2: Use Variables
  • 16 An Introduction to Advanced Techniques
  • Debugging Scripts
  • Types of Errors
  • JavaScript and Accessibility
  • Separate Content from Presentation
  • Enhancing Content
  • Try This 16-1: Make This Code Accessible
  • Using Cookies
  • Setting a Cookie
  • Reading a Cookie
  • Try This 16-2: Remember a Name
  • Working with Images
  • Preloading
  • Rollovers
  • JavaScript Security
  • Security and Signed Scripts
  • Page Protection
  • AJAX
  • JavaScript Libraries
  • A: Answers to Self Tests
  • Chapter 1: Introduction to JavaScript
  • Chapter 2: Placing JavaScript in an HTML File
  • Chapter 3: Using Variables
  • Chapter 4: Using Functions
  • Chapter 5: JavaScript Operators
  • Chapter 6: Conditional Statements and Loops
  • Chapter 7: Event Handlers
  • Chapter 8: Objects
  • Chapter 9: The Document Object
  • Chapter 10: Window Object
  • Chapter 11: JavaScript Arrays
  • Chapter 12: Math, Number, and Date Objects
  • Chapter 13: Handling Strings
  • Chapter 14: JavaScript and Forms
  • Chapter 15: JavaScript and Frames
  • Chapter 16: An Introduction to Advanced Techniques
  • Index