You are previewing Javascript for the World Wide Web: Visual Quickstart Guide, Fifth Edition.
O'Reilly logo
Javascript for the World Wide Web: Visual Quickstart Guide, Fifth Edition

Book Description

The Web doesn¿t stand still¿not even for a minute¿and neither do the languages that Web pages are based on. That¿s why you need this eagerly anticipated update to the popular JavaScript for the World Wide Web: Visual QuickStart Guide. Through a combination of task-based instruction and strong visuals, best-selling authors and Web gurus Tom Negrino and Dori Smith take you step by step through all of today¿s JavaScript essentials: creating navigation bars and other user interface elements, producing dynamic images and smart forms, controlling and detecting browsers, creating and manipulating windows, validating user entries in Web forms, and more. Whether you¿re a beginning scripter who wants a thorough introduction to the topic or a more advanced scripter who needs a convenient reference, you¿ll find what you need here¿in straightforward language peppered with tips and techniques drawn from the authors¿ years of experience. By the end of the volume, you¿ll be able to smoothly integrate HTML, JavaScript, and CSS to bring your Web sites to life.

Table of Contents

  1. Copyright
    1. Dedication:
    2. Special Thanks to:
  2. Introduction
    1. We wrote this book for you
    2. How to use this book
    3. You say browser, we say Kumbaya
    4. Don't type that code!
    5. Time to get started
  3. 1. Getting Acquainted with JavaScript
    1. What JavaScript Is
    2. JavaScript Isn't Java
    3. Where JavaScript Came From
    4. What JavaScript Can Do
    5. What JavaScript Can't Do
    6. The Snap-together Language
      1. Objects
      2. Properties
      3. Methods
      4. Putting the pieces together
    7. Handling Events
    8. Values and Variables
      1. Operators
    9. Assignments and Comparisons
      1. Comparisons
    10. What Tools to Use?
  4. 2. Start Me Up!
    1. Where to Put Your Scripts
      1. To write your first script
    2. Hiding Scripts from Old Browsers
      1. To hide JavaScript from old browsers
    3. Putting Comments in Scripts
      1. To comment your script
    4. Alerting the User
      1. To alert a user
    5. Confirming a User's Choice
      1. More about conditionals
      2. To confirm a choice
    6. Prompting the User
      1. To prompt a user for a response
    7. Redirecting the User
      1. To redirect a user
    8. Redirecting the User with a Link
      1. To perform a smoother redirection
    9. Browser Detection
      1. To discover the user's browser type
  5. 3. Language Essentials
    1. Detecting Browser Plug-ins
      1. (Netscape and Internet Explorer/Mac)
      2. To check for a plug-in
    2. Around and Around with Loops
      1. (Netscape and Internet Explorer/Mac)
      2. More about loops
      3. To use a loop to check for plug-ins
    3. Writing with Loops
      1. (Netscape and Internet Explorer/Mac)
      2. To write a Web page using a loop
    4. Using For/In Loops
      1. (Netscape and Internet Explorer/Mac)
      2. To use a for/in loop
    5. Using Do/While Loops
      1. To use a do/while loop
    6. Checking if Java Is Enabled
      1. To check if Java is enabled
    7. Functions
      1. Calling a function
      2. Passing information to a function
    8. Using Multi-level Conditionals
      1. To use a switch/case statement
    9. Working with Functions That Return Values
      1. (Netscape and Internet Explorer/Mac)
      2. To return a value from a function:
    10. Handling Errors
      1. To handle errors gracefully
    11. Putting More than One Script on a Page
    12. Scrolling Status Bars
      1. To make a scrolling status bar
    13. Status Bar Messages
      1. To put a message in the status bar
  6. 4. Image Basics
    1. Creating Rollovers
      1. To create a rollover
    2. Creating More Effective Rollovers
      1. To create a better rollover
    3. Putting Multiple Rollovers on a Page
      1. To put multiple rollovers on a page
    4. Triggering Rollovers from a Link
      1. To trigger a rollover from a link
    5. Making Multiple Links Change a Single Rollover
      1. To make multiple links change a single rollover
    6. Working with Multiple Rollovers
      1. To work with multiple rollovers
    7. Using a Function to Code Multiple Images with a Single Rollover
      1. To use a function with multiple image rollovers
    8. Using a Function to Code Multiple Rollovers
      1. To use a function to simplify multiple rollovers
  7. 5. More Fun with Images
    1. Creating Cycling Banners
      1. To create cycling banners
    2. Creating Multiple Cycling Banners
      1. To create multiple cycling banners
    3. Making the Banner Cycling Wait for the User
      1. To make the cycling wait for the user
    4. Adding Links to Cycling Banners
      1. To add links to cycling banners
    5. Building Slideshows
      1. To make a slideshow
    6. Building Wraparound Slideshows
      1. To build a wraparound slideshow
    7. Displaying a Random Image
      1. To display a random image
    8. Cycling Images with a Random Start
      1. To start images cycling from a random start
    9. Displaying Multiple Random Images
      1. To display multiple random images
    10. Combining a Rollover with an Image Map
      1. To combine a rollover with an image map
  8. 6. Frames, Frames, and More Frames
    1. Keeping a Page out of a Frame
      1. To isolate your page
    2. Forcing a Page into a Frame
      1. To force a page into a frame
    3. Forcing a Site into a Frame
      1. To force a site into a frame
    4. Loading a Frame
      1. To load one frame from another
    5. Creating and Loading a Dynamic Frame
      1. To load a dynamic frame from another frame
    6. Sharing Functions Between Frames
      1. To use a function on another page
    7. Storing Information in Frames
      1. To keep a count of page visits
    8. Loading Multiple Frames at Once
      1. To load multiple frames at once
    9. Browser Detection with Frames
      1. To detect browser capabilities with frames
    10. Working with Iframes
      1. To create the content for an iframe
  9. 7. Working with Browser Windows
    1. Opening a New Window
      1. To open a new window
    2. Loading Different Contents into a Window
      1. To load different contents into a window
    3. Opening a New Window Using an Image Link
      1. To open new windows using image links
    4. Opening Multiple Windows
      1. To open multiple windows with a script
    5. Opening Multiple Windows Simultaneously
      1. To open multiple windows at the same time
    6. Scrolling a Window
      1. To scroll a window
    7. Updating One Window from Another
      1. To update one window from another
    8. Creating New Pages with JavaScript
      1. To create a new page with JavaScript
    9. Closing a Window
      1. To close a window
    10. Creating a Control Panel
      1. To create a control panel
    11. Positioning a Window on the Screen
      1. To position a window on the screen
    12. Displaying an Alert when a Window is Loaded
      1. To display an alert when a window is loaded
  10. 8. Form Handling
    1. Verifying Passwords
      1. To verify a password entry
    2. Using Images as Submit Buttons
      1. To use an image as a submit button
    3. Select-and-Go Navigation
      1. To create a select-and-go menu
    4. Changing Menus Dynamically
      1. To change menus dynamically
    5. Selecting Menu Items
      1. To require a menu choice
    6. Working with Radio Buttons
      1. To make sure that the user picks a radio button
    7. Setting One Field with Another
      1. To check for proper entry
      2. To set a field value automatically
    8. Validating Zip Codes
      1. To make sure Zip codes are numeric
    9. Validating Email Addresses
      1. To validate an email address
  11. 9. Forms and Regular Expressions
    1. Validating an Email Address with regular Expressions
      1. To validate an email address using regular expressions
      2. Validating a File Name
        1. To validate a URL:
      3. Extracting Strings
        1. To extract strings
      4. Formatting Strings
        1. To format a string
      5. Formatting and Sorting Strings
        1. To format and sort strings
      6. Formatting and Validating Strings
        1. To format and validate a phone number
  12. 10. Making Your Pages Dynamic
    1. Putting the Current Date into a Web Page
      1. To put the current date into a Web page
    2. Working with Days
      1. To figure out if it is a weekend
    3. Customizing a Message for the Time of Day
      1. To customize messages for the time of day
    4. Displaying Dates by Time Zone
      1. To display dates by time zone
    5. Converting Military Time to AM/PM
      1. To convert military time to AM/PM
    6. Creating a Countdown
      1. To create a countdown
    7. Working with Referrer Pages
      1. To display the referrer page
    8. Writing Text into a Document on the Fly
      1. To write text on the fly
    9. Date Methods
  13. 11. Handling Events
    1. Handling Window Events
      1. The onload event
      2. The onunload event
      3. The onresize event
      4. The onmove event
      5. The onabort event
      6. The onerror event
      7. The onfocus event
      8. The onblur event
    2. Mouse Event Handling
      1. The onmousedown event
      2. The onmouseup event
      3. The onmousemove event
      4. The onmouseover event
      5. The onmouseout event
      6. The ondblclick event
      7. The onclick event
    3. Form Event Handling
      1. The onsubmit event
      2. The onreset event
      3. The onchange event
      4. The onselect event
      5. The onclick event
      6. The onblur event
      7. The onfocus event
    4. Key Event Handling
      1. The onkeydown event
      2. The onkeyup event
      3. The onkeypress event
  14. 12. JavaScript and Cookies
    1. Baking Your First Cookie
      1. To set a cookie
    2. Reading a Cookie
      1. To read a cookie
    3. Showing Your Cookies
      1. To show all your cookies
    4. Using Cookies as Counters
      1. To use a cookie as a counter
    5. Deleting Cookies
      1. To delete cookies
    6. Handling Multiple Cookies
      1. To handle multiple cookies
    7. Displaying “New to You” Messages
      1. To display a “New to You” message
  15. 13. Introducing CSS
    1. Saying it with Style
      1. To add a style to your page
    2. Styles with Class
      1. To format text with CSS
    3. Changing Fonts with CSS
      1. To change fonts with CSS
    4. Checking Your ID
      1. To add an ID to your style sheet
    5. Styles and Spans
      1. To use a <span>
    6. Distinguished Links
      1. To enhance your links
    7. Positioning Absolutely
      1. To use absolute positioning
  16. 14. Working with DHTML
    1. DHTML Browsers & “Standards”
    2. Moving an Object in Two Dimensions
      1. (Netscape 4.x only)
      2. To move a Netscape DHTML object
    3. Moving an Object in Two Dimensions
      1. (Internet Explorer Win/Mac)
      2. To move an Internet Explorer DHTML object
    4. Moving an Object in Two Dimensions
      1. (Netscape 6+ only)
      2. To move a Netscape 6 DHTML object
    5. Moving an Object in Two Dimensions
      1. To move a cross-browser DHTML object
    6. Moving an Object in Three Dimensions
      1. (Netscape 4.x only)
      2. To move a DHTML object in Netscape
    7. Moving an Object in Three Dimensions
      1. (Netscape 6+ only)
    8. Moving an Object in Three Dimensions
      1. (Cross-browser)
      2. To move a cross-browser DHTML object
    9. Moving DHTML Text
      1. To move DHTML text in all browsers
    10. Modifying a DHTML Drop Shadow
      1. (IE Windows)
      2. To modify a drop shadow
    11. Rotating a DHTML Shadow
      1. (IE Windows)
      2. To rotate a shadow
    12. Modifying a DHTML Glow
      1. (IE Windows)
      2. To modify a DHTML glow
  17. 15. User Interface Design with JavaScript
    1. Pull-Down Menus
      1. To create a pull-down menu
    2. Sliding Menus
      1. To use sliding menus
    3. Tool Tips
      1. To create tool tips
    4. Click-Anywhere Form Fields
      1. To create click-anywhere form fields
  18. 16. Applied JavaScript
    1. Using an External .js File
      1. To use an external .js file
    2. A Slideshow with Captions
      1. To create a slideshow with captions
    3. A Silly Name Generator
      1. To combine JavaScript techniques
    4. Bar Graph Generator
      1. To generate a bar graph
    5. An Object-oriented Bar Graph Generator
      1. To generate a bar graph with custom objects
    6. Style Sheet Switcher
      1. To allow the user to switch between style sheets
  19. 17. Manipulating Nodes
    1. About Node Manipulation
      1. DOM-2 and the W3C
      2. DOM-2 terminology
    2. Adding Nodes
      1. To add nodes
    3. Deleting Nodes
      1. To delete nodes
    4. Deleting Specific Nodes
      1. To delete a particular node
    5. Inserting Nodes
      1. To insert a node
    6. Replacing Nodes
      1. To replace nodes
  20. 18. Bookmarklets
    1. Your First Bookmarklet
      1. To create a bookmarklet (Netscape 4)
      2. To create a bookmarklet (Netscape 6+)
      3. To create a bookmarklet (Safari)
      4. To create a bookmarklet (Internet Explorer/Mac 5)
      5. To create a bookmarklet (Internet Explorer/Win 5+)
    2. Changing a Page's Background Color
      1. To change the background color
    3. Web-safe Colors
      1. To show a Web-safe color chart
    4. Word Lookups
      1. To look up a word
    5. Viewing Images
      1. To view images (in Netscape 4)
      2. To view images (in Netscape 6+, Safari, and Internet Explorer):
    6. Displaying ISO Latin Characters
      1. To display ISO Latin characters
    7. Converting RGB Values to Hex
      1. To convert RGB values to hexadecimal:
    8. Converting Values
      1. To convert kilometers to miles
    9. A Bookmarklet Calculator
      1. To use a JavaScript calculator
  21. 19. Working with Visual Tools
    1. The Pros and Cons of Visual Tools
      1. The Good Side
      2. The Dark Side
    2. Using Behaviors in Dreamweaver
      1. To validate a form with a behavior
    3. Flying Objects in Adobe GoLive
      1. To animate objects in Adobe GoLive
    4. Creating Pop-Up Menus in Fireworks
      1. To create a pop-up menu with Fireworks MX
    5. Customizing Dreamweaver
      1. Behaviors
      2. Commands
      3. Inspectors
      4. Menus
      5. Objects
      6. Start-up
  22. 20. Debugging Common Errors
    1. The Built-in Debugging Aids
      1. Microsoft
      2. Netscape
      3. To use Netscape 7's console
    2. JavaScript Debuggers
      1. Microsoft
      2. Macromedia
    3. Common Errors
      1. To debug your scripts, look for these gotchas
    4. Following Variables While a Script is Running
      1. To view variables during script execution
    5. Viewing Variables in Another Window
      1. To write debugging info to a separate window:
    6. Writing Error Messages to Another Window
      1. To create your own error messages
  23. A. JavaScript Genealogy and Reference
    1. JavaScript Versions
      1. Netscape's JavaScript
      2. Microsoft's JScript
      3. AOL
    2. ECMAScript
    3. Browsers and JavaScript
    4. Object Flowchart
    5. The Big Object Table
  24. B. JavaScript Reserved Words
    1. JavaScript reserved words
    2. Additional words reserved for future use by ECMAScript 3
    3. ECMAScript 4
    4. Other identifiers to avoid
  25. C. Cascading Style Sheets Reference
  26. D. Where to Learn More
    1. Finding Help on the Web
      1. Netscape and Mozilla sites
      2. Core JavaScript Guide 1.5
      3. Core JavaScript Reference 1.5
      4. Using Web Standards in Your Web Pages
      5. Other great JavaScript sites
      6. Microsoft's JScript Web page
      7. EarthWeb's JavaScript site
      8. Builder.com
      9. WebReference
      10. Doc JavaScript
      11. Peter-Paul Koch's JavaScript site
      12. Script Repositories
      13. JavaScript Kit
      14. Dynamic Drive
      15. JavaScript Source
      16. Usenet Newsgroups
    2. Books
      1. JavaScript, The Definitive Guide
      2. Dynamic HTML: The Definitive Reference
      3. JavaScript Bible
      4. JavaScript & DHTML Cookbook