Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
JavaScript: The Missing Manual
A Note Regarding Supplemental Files
The Missing Credits
About the Author
About the Creative Team
Acknowledgements
The Missing Manual Series
Introduction
What Is JavaScript?
A Bit of History
JavaScript Is Everywhere
JavaScript Doesn’t Stand Alone
HTML: The Barebones Structure
How HTML Tags Work
CSS: Adding Style to Web Pages
Anatomy of a Style
Software for JavaScript Programming
Free Programs
Commercial Software
About This Book
This Book’s Approach to JavaScript
About the Outline
Living Examples
About MissingManuals.com
The Very Basics
About → These → Arrows
Safari® Books Online
I. Getting Started with JavaScript
1. Writing Your First JavaScript Program
Introducing Programming
What’s a Computer Program?
How to Add JavaScript to a Page
External JavaScript Files
Your First JavaScript Program
Writing Text on a Web Page
Attaching an External JavaScript File
Tracking Down Errors
The Firefox JavaScript Console
Displaying the Internet Explorer Error Dialog Box
Accessing the Safari Error Console
2. The Grammar of JavaScript
Statements
Commands
Types of Data
Numbers
Strings
Booleans
Variables
Creating a Variable
Using Variables
Working with Data Types and Variables
Basic Math
The Order of Operations
Combining Strings
Combining Numbers and Strings
Changing the Values in Variables
Tutorial: Using Variables to Create Messages
Tutorial: Asking for Information
Arrays
Creating an Array
Accessing Items in an Array
Adding Items to an Array
Adding an item to the end of an array
Adding an item to the beginning of an array
Choosing how to add items to an array
Deleting Items from an Array
Adding and Deleting with splice()
Deleting items with splice()
Adding items with splice()
Replacing items with splice()
Tutorial: Writing to a Web Page Using Arrays
Comments
When to Use Comments
Comments in this Book
3. Adding Logic and Control to Your Programs
Making Programs React Intelligently
Conditional Statement Basics
Adding a Backup Plan
Testing More Than One Condition
More Complex Conditions
Making sure more than one condition is true
Making sure at least one condition is true
Negating a condition
Nesting Conditional Statements
Tips for Writing Conditional Statements
Tutorial: Using Conditional Statements
Handling Repetitive Tasks with Loops
While Loops
Loops and Arrays
For Loops
Do/While Loops
Functions: Turn Useful Code Into Reusable Commands
Mini-Tutorial
Giving Information to Your Functions
Retrieving Information from Functions
Keeping Variables from Colliding
Tutorial: A Simple Quiz
4. Working with Words, Numbers, and Dates
A Quick Object Lesson
Strings
Determining the Length of a String
Changing the Case of a String
Searching a String: indexOf() Technique
Extracting Part of a String with slice()
Finding Patterns in Strings
Creating and Using a Basic Regular Expression
Building a Regular Expression
Grouping Parts of a Pattern
Useful Regular Expressions
U.S. Zip code
U.S. phone number
Email address
Date
Web address
Matching a Pattern
Matching every instance of a pattern
Replacing Text
Trying Out Regular Expressions
Numbers
Changing a String to a Number
Testing for Numbers
Rounding Numbers
Formatting Currency Values
Creating a Random Number
Randomly selecting an array element
A function for selecting a random number
Dates and Times
Getting the Month
Getting the Day of the Week
Getting the Time
Changing hours to a.m. and p.m.
Padding single digits
Creating a Date Other Than Today
Creating a date that’s one week from today
Tutorial
Overview
Writing the Function
5. Dynamically Modifying Web Pages
Modifying Web Pages: An Overview
Understanding the Document Object Model
Selecting a Page Element
getElementById()
getElementsByTagName()
Selecting nearby nodes
Adding Content to a Page
The Moon Quiz Revisited
The Problem with the DOM
Introducing JavaScript Libraries
Getting Started with jQuery
Selecting Page Elements (Revisited)
Basic Selectors
ID selectors
Element selectors
Class selectors
Advanced Selectors
jQuery Filters
Understanding jQuery Selections
Automatic loops
Chaining functions
Adding Content to a Page
Replacing and Removing Selections
Setting and Reading Tag Attributes
Classes
Reading and Changing CSS Properties
Changing Multiple CSS Properties at Once
Reading, Setting, and Removing HTML Attributes
Creative Headlines
Acting on Each Element in a Selection
Anonymous Functions
this and $(this)
Automatic Pull Quotes
Overview
Programming
6. Action/Reaction: Making Pages Come Alive with Events
What Are Events?
Mouse Events
Document/Window Events
Form Events
Keyboard Events
Using Events with Functions
Inline Events
The Traditional Model
The Modern Way
The jQuery Way
Tutorial: Highlighting Table Rows
More jQuery Event Concepts
Waiting for the HTML to Load
jQuery Events
The hover() event
The toggle() Event
The Event Object
Stopping an Event’s Normal Behavior
Removing Events
Advanced Event Management
Tutorial: A One-Page FAQ
Overview of the Task
The Programming
7. Improving Your Images
Swapping Images
Changing an Image’s src Attribute
Preloading Images
Rollover Images
Tutorial: Adding Rollover Images
Overview of the Task
The Programming
jQuery Effects
Basic Showing and Hiding
Fading Elements In and Out
Sliding Elements
Animation
Tutorial: Photo Gallery with Effects
Overview of Task
The Programming
Advanced Gallery with jQuery lightBox
The Basics
Customizing lightBox
lightBox options
lightBox images
lightBox CSS
Tutorial: lightBox Photo Gallery
Animated Slideshows with Cycle
The Basics
Customizing the Cycle Plug-in
Effects
Speed
Navigating slides
Starting and stopping the slideshow
Tutorial: An Automated Slideshow
II. Building Web Page Features
8. Improving Navigation
Some Link Basics
Selecting Links with JavaScript
Determining a Link’s Destination
Don’t Follow That Link
Opening External Links in a New Window
Creating New Windows
Window Properties
Use the window reference
Events that can open a new window
Opening Pages in a Window on the Page
Customizing the Look of a Greybox Window
Tutorial: Opening a Page Within a Page
Tutorial: Making Bigger Links
Overview
The Programming
Animated Navigation Menus
The HTML
The CSS
The JavaScript
The Tutorial
9. Enhancing Web Forms
Understanding Forms
Selecting Form Elements
Getting and Setting the Value of a Form Element
Determine Whether Buttons and Boxes Are Checked
Form Events
Submit
Focus
Blur
Click
Change
Adding Smarts to Your Forms
Focus the First Field in a Form
Disabling and Enabling Fields
Hiding and Showing Form Options
Tutorial: Basic Form Enhancements
Focusing a Field
Disabling Form Fields
Hiding Form Fields
Form Validation
jQuery Validation Plug-in
Basic Validation
Adding validation rules
Adding error messages
Advanced Validation
Advanced rules
Advanced error messages
Styling Error Messages
Validation Tutorial
Basic Validation
Advanced Validation
Validating Checkboxes and Radio Buttons
Formatting the Error Messages
10. Expanding Your Interface
Hiding Information with Accordion Panels
Customizing an Accordion
Accordion Tutorial
Organizing Information in Tabbed Panels
Formatting Tabs and Panels
A required class style
The tab group
Tabs
Panels
Customizing the Tabs Plug-in
Selecting a tab when the page loads
Using a different event to open a panel
Automating the display of panels
Tabbed Panels Tutorial
Tooltips
Tooltips Using the Title Attribute
Tooltips Using Another Web Page
Tooltips Using Hidden Content
Controlling the Display of Tooltips
Formatting Tooltips
Cluetip Tutorial
Adding a tooltip using the title attribute
Adding a tooltip using another Web page
Adding a tooltip using HTML on the page
Creating Sortable Tables
Styling the Table
Using the Tablesorter plug-in to stripe tables
Tablesorter Tutorial
III. Ajax: Communicating with the Web Server
11. Introducing Ajax
What Is Ajax?
Ajax: The Basics
Pieces of the Puzzle
Talking to the Web Server
Ajax the jQuery Way
Using the load() Function
Tutorial: The load() Function
Overview
The programming
The get() and post() Functions
Formatting Data to Send to the Server
Query string
Object literal
jQuery’s serialize() function
Processing Data from the Server
Tutorial: Using the post() Function
Overview
The programming
JSON
Accessing JSON Data
Complex JSON Objects
12. Basic Ajax Programming
Tabs Plug-in
Changing the Loading Text and Icon
Turning off the “Loading” message
Ajax Tabs Tutorial
Adding Google Maps to Your Site
Setting a Location for the Map
Other jMap Options
Adding Markers and HTML Bubbles
Get Driving Directions
jMaps Tutorial
IV. Troubleshooting, Tips, and Tricks
13. Troubleshooting and Debugging
Top JavaScript Programming Mistakes
Non-Closed Pairs
Quotation Marks
Using Reserved Words
Single Equals in Conditional Statements
Case-Sensitivity
Incorrect Path to External JavaScript File
Incorrect Paths Within External JavaScript Files
Disappearing Variables and Functions
Debugging with Firebug
Installing and Turning On Firebug
Viewing Errors with Firebug
Using console.log() to Track Script Progress
Tutorial: Using the Firebug Console
More Powerful Debugging
Controlling your script with the debugger
Watching your script
Debugging Tutorial
14. Going Further with JavaScript
Putting It All Together
Using External JavaScript Files
Writing More Efficient JavaScript
Put Preferences in Variables
Ternary Operator
The Switch Statement
Using the jQuery Object Efficiently
Creating Fast-Loading JavaScript
Using YUI Compressor for Windows
Using YUI Compressor for Mac
V. Appendix
A. JavaScript Resources
References
Web Sites
Books
Basic JavaScript
Articles and Presentations
Web Sites
Books
jQuery
Articles
Web Sites
Books
The Document Object Model
Articles and Presentations
Web Sites
Books
Ajax
Web Sites
Books
Advanced JavaScript
Articles and Presentations
Web Sites
Books
CSS
Web Sites
Books
JavaScript Software
Index
About the Author
Colophon
← Prev
Back
Next →
← Prev
Back
Next →