Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
JavaScript Step by Step, Second Edition
A Note Regarding Supplemental Files
Acknowledgements
Introducing JavaScript Step by Step, Second Edition
Who Should Read This Book?
Features and Conventions of This Book
What’s in the Companion Content
Downloading the Companion Content
Minimum System Requirements
Getting Help
Getting Help with This Book and the Companion Content
I. JavaWhat? The Where, Why, and How of JavaScript
1. JavaScript Is More Than You Might Think
A Brief History of JavaScript
Enter Internet Explorer 3.0
And Then Came ECMAScript
So Many Standards...
The DOM
What’s in a JavaScript Program?
Using the javascript pseudo-protocol and a function
JavaScript Placement on Your Webpage
What JavaScript Can Do
What JavaScript Can’t Do
JavaScript Can’t Be Forced on a Client
JavaScript Can’t Guarantee Data Security
JavaScript Can’t Cross Domains
JavaScript Doesn’t Do Servers
Tips for Using JavaScript
Where JavaScript Fits
Which Browsers Should the Site Support?
What’s New in ECMAScript Version 5?
New Array Methods
New Controls on Object Properties
New JSON Object
Changes to the Date Object
A New Strict Mode
Browser Support
Exercises
2. Developing in JavaScript
JavaScript Development Options
Configuring Your Environment
Writing JavaScript with Visual Studio 2010
Your First Web (and JavaScript) Project with Visual Studio 2010
Creating a web project with JavaScript in Visual Studio 2010
Using External JavaScript Files with Visual Studio 2010
Creating an external file for JavaScript using Visual Studio 2010
Writing JavaScript with Eclipse
Your First Web (and JavaScript) Project with Eclipse
Creating a web project with JavaScript in Eclipse
Using External JavaScript Files with Eclipse
Creating an external file for JavaScript using Eclipse
Writing JavaScript Without an IDE
Your First Web (and JavaScript) Project with Notepad
Creating a webpage with JavaScript in Notepad
Using External JavaScript Files Without an IDE
Creating an external file for JavaScript using Notepad
Debugging JavaScript
Exercises
3. JavaScript Syntax and Statements
A Bit of Housekeeping
Case Sensitivity
White Space
Comments
Semicolons
Line Breaks
Placing JavaScript Correctly
JavaScript Statements
What’s in a Statement?
The Two Types of JavaScript Statements
Reserved Words in JavaScript
A Quick Look at Functions
Placing JavaScript with a user-defined function
JavaScript’s New Strict Mode
Exercises
4. Working with Variables and Data Types
Data Types in JavaScript
Working with Numbers
Performing hexadecimal math with JavaScript
Numeric Functions
Testing the isNaN() function
The Math Object
Working with Strings
Escaping Quotation Marks
Other Escape Characters
Using escape sequences
String Methods and Properties
Obtaining the length of a string
Booleans
Null
Undefined
Objects
Arrays
Defining and Using Variables
Declaring Variables
Variable Types
Variable Scope
Examining variable scope
Installing Firebug
Troubleshooting with Firebug
The Date Object
Writing the date and time to a webpage
Counting down to a certain date in the future
Calculating render time
Using the RegExp Object
The Syntax of Regular Expressions
References and Garbage Collection
Learning About Type Conversions
Number Conversions
String Conversions
Boolean Conversions
Exercises
5. Using Operators and Expressions
Meet the Operators
Additive Operators
Multiplicative Operators
Bitwise Operators
Equality Operators
Testing the equality operators
Relational Operators
The in Operator
The instanceof Operator
Unary Operators
Incrementing and Decrementing
Converting to a Number with the Plus Sign
Creating a Negative Number with the Minus Sign
Negating with bitwise not and logical not
Using the delete Operator
Using the delete operator with objects
Returning Variable Types with the typeof Operator
Using the typeof operator
The void Operator
Assignment Operators
The Comma Operator
Exercises
II. Applying JavaScript
6. Controlling Flow with Conditionals and Loops
If (and How)
Syntax for if Statements
The prompt() Function in Internet Explorer
Using if to make decisions about program flow
Compound Conditions
Using else if and else Statements
Using multiple levels of conditionals and a regular expression
Working with Ternary Conditionals
Testing with switch
Looping with while
The while Statement
Making Sure the Code Executes at Least Once
Changing the Condition
The do...while Statement
Using for Loops
The for Loop
Using a for loop with an array
The for...in Loop
Using a for...in loop
The for each...in Loop
Validating Forms with Conditionals
Validating input with a conditional statement
Exercises
7. Working with Functions
What’s in a Function?
Function Arguments
Variable Scoping Revisited
Return Values
More on Calling Functions
Anonymous/Unnamed Functions (Function Literals)
Closures
Methods
A Look at Dialog Functions
Obtaining input with confirm()
Exercises
8. Objects in JavaScript
Object-Oriented Development
Objects
Properties
Methods
Classes
Creating Objects
Adding Properties to Objects
Displaying Object Properties
Looping through object properties
Looking for a Property
Adding Methods to Objects
Finding Out More About Arrays
The length Property
Array Methods
Adding and Removing Elements
Adding elements with concat()
Taking Advantage of Built-in Objects
The Global Object
Making URIs Safe
Using the eval() method
Exercises
9. The Browser Object Model
Introducing the Browser
The Browser Hierarchy
Events
A Sense of Self
Getting Information About the Screen
Determining a visitor’s screen height and width
Using the navigator Object
Looking at the navigator object
Using the navigator object to detect Java
The location Object
Looking at the location object
The history Object
Exercises
III. Integrating JavaScript into Design
10. The Document Object Model
The Document Object Model Defined
DOM Level 0: The Legacy DOM
DOM Levels 1 and 2
The DOM as a Tree
Working with Nodes
Retrieving Elements
Retrieving Elements by ID
Retrieving by Tag Name
HTML Collections
Working with Siblings
Working with Attributes
Viewing Attributes
Retrieving element attributes
Setting Attributes
Creating Elements
Adding Text
Adding an Element and Setting an ID
Deleting Elements
Exercises
11. JavaScript Events and the Browser
Understanding Window Events
The Event Models
Using the DOM 0 Model
Newer Event Models: W3C and Internet Explorer
A Generic Event Handler
Detecting Visitor Information
A Brief Look at the userAgent Property
Feature Testing
Keeping JavaScript Away from Older Browsers
Other navigator Properties and Methods
Opening, Closing, and Resizing Windows
Window Opening Best Practices
Opening Tabs: No JavaScript Necessary?
Resizing and Moving Windows
Timers
Exercises
12. Creating and Consuming Cookies
Understanding Cookies
Creating Cookies with JavaScript
Looking at a Simple Cookie
Setting a Cookie’s Expiration Date
Adding an expiration date to a cookie
Setting the Cookie Path
Setting the Cookie Domain
Working with Secure Cookies
Reading Cookies with JavaScript
Removing Cookies
Exercises
13. Working with Images in JavaScript
Working with Image Rollovers
A Simple Rollover
Modern Rollovers
Creating portable rollovers
Preloading Images
Working with Slideshows
Creating a Slideshow
Moving Backward
Creating a Previous button
Working with Image Maps
Exercises
14. Using JavaScript with Web Forms
JavaScript and Web Forms
Obtaining Form Data
Working with Form Information
Working with Select Boxes
Selecting an option with JavaScript
Working with Check Boxes
Working with Radio Buttons
Prevalidating Form Data
Hacking JavaScript Validation
Validating a Text Field
Exercises
15. JavaScript and CSS
What Is CSS?
Using Properties and Selectors
Applying CSS
The Relationship Between JavaScript and CSS
Setting Element Styles by ID
Using CSS and JavaScript for form validation
Setting Element Styles by Type
Setting CSS Classes with JavaScript
Retrieving Element Styles with JavaScript
Modifying Style Sheets with JavaScript
Exercises
16. JavaScript Error Handling
Introducing Two Ways to Handle Errors
Using try/catch
Using try/catch with a web form
And Finally...
Using the onerror Event
Attaching onerror to the window Object
Ignoring Errors
Attaching onerror to the image Object
Exercises
IV. AJAX and Server-Side Integration
17. JavaScript and XML
Using XML with JavaScript
Looking at an Example XML Document
Loading an XML Document with JavaScript
Importing the Document
Displaying the Document
Adding column headings from an XML document
Working with XML Data from Excel 2007
A Preview of Things to Come
Exercises
18. JavaScript Applications
Components of JavaScript Applications
The Big Three: Display, Behavior, Data
Display: Page Layout
Behaviors: Controlling What Happens When
Data: Consume, Display, and Validate
JavaScript and Web Interfaces
19. A Touch of AJAX
Introduction to AJAX
The XMLHttpRequest Object
Instantiating the XMLHttpRequest Object
Sending an AJAX Request
Processing an AJAX Response
Sending and receiving with XMLHttpRequest
Processing XML Responses
Working with JSON
Processing Headers
Using the POST Method
Case Study: Live Searching and Updating
Exercises
20. A Bit Deeper into AJAX
Creating an HTML Table with XML and CSS
Using XMLHttpRequest to retrieve and display XML data
Styling the Table with CSS
Changing Style Attributes with JavaScript
Creating a Dynamic Drop-Down Box
Accepting Input from the User and AJAX
Exercises
V. jQuery
21. An Introduction to JavaScript Libraries and Frameworks
Understanding Programming Libraries
Defining Your Own JavaScript Library
Creating a library
Looking at Popular JavaScript Libraries and Frameworks
jQuery
Yahoo! User Interface
MooTools
Other Libraries
Exercises
22. An Introduction to jQuery
jQuery Primer
Using jQuery
The Two jQuery Downloads
Including jQuery
Basic jQuery Syntax
Connecting jQuery to the Load Event
Using Document Ready
Using Selectors
Selecting Elements by ID
Selecting Elements by Class
Selecting Elements by Type
Selecting Elements by Hierarchy
Selecting Elements by Position
Selecting Elements by Attribute
Selecting Form Elements
More Selectors
Functions
Traversing the DOM
Working with Attributes
Changing Text and HTML
Inserting Elements
Callback Functions
Events
Binding and Unbinding
Mouse Events and Hover
Many More Event Handlers
AJAX and jQuery
Using AJAX with jQuery
AJAX Errors and Timeouts
Sending Data to the Server
Other Important Options
More jQuery
Exercises
23. jQuery Effects and Plug-Ins
Core Features for Enhancing Usability
Native Effects
Show, Hide, and Toggle
Adding a duration
Fade In and Fade Out
Sliding
jQuery UI
Using jQuery UI
Drag and Drop
Accordion
Setting default state for an accordion
More jQuery UI
Exercises
A. Answer Key to Exercises
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Chapter 8
Chapter 9
Chapter 10
Chapter 11
Chapter 12
Chapter 13
Chapter 14
Chapter 15
Chapter 16
Chapter 17
Chapter 18
Chapter 19
Chapter 20
Chapter 21
Chapter 22
Chapter 23
B. About the Author
Index
About the Author
← Prev
Back
Next →
← Prev
Back
Next →