Buying Options
JavaScript & DHTML Cookbook
Ebook $27.99
Add to Cart
Safari Books Online
Add to Cart
What is this?

Product Editions

Please consider the latest edition.

  1. JavaScript & DHTML Cookbook, Second Edition - August 2007
  2. JavaScript & DHTML Cookbook - April 2003
Description
On numerous online forums for JavaScript and DHTML, the majority of questions begin with "How do I...?" This new Cookbook provides the answers with a comprehensive collection of problems, solutions, and practical examples. The book's recipes range from simple tasks, such as manipulating strings and validating dates in JavaScript, to entire libraries that demonstrate complex tasks, such as cross-browser positioning of HTML elements and sorting tables.
Full Description
Table of Contents
  1. Chapter 1 Strings

    1. Introduction

    2. Concatenating (Joining) Strings

    3. Accessing Substrings

    4. Changing String Case

    5. Testing Equality of Two Strings

    6. Testing String Containment Without Regular Expressions

    7. Testing String Containment with Regular Expressions

    8. Searching and Replacing Substrings

    9. Using Special and Escaped Characters

    10. Reading and Writing Strings for Cookies

    11. Converting Between Unicode Values and String Characters

    12. Encoding and Decoding URL Strings

    13. Encoding and Decoding Base64 Strings

  2. Chapter 2 Numbers and Dates

    1. Introduction

    2. Converting Between Numbers and Strings

    3. Testing a Number's Validity

    4. Testing Numeric Equality

    5. Rounding Floating-Point Numbers

    6. Formatting Numbers for Text Display

    7. Converting Between Decimal and Hexadecimal Numbers

    8. Generating Pseudorandom Numbers

    9. Calculating Trigonometric Functions

    10. Creating a Date Object

    11. Calculating a Previous or Future Date

    12. Calculating the Number of Days Between Two Dates

    13. Validating a Date

  3. Chapter 3 Arrays and Objects

    1. Introduction

    2. Creating a Simple Array

    3. Creating a Multidimensional Array

    4. Converting Between Arrays and Strings

    5. Doing Something with the Items in an Array

    6. Sorting a Simple Array

    7. Combining Arrays

    8. Dividing Arrays

    9. Creating a Custom Object

    10. Simulating a Hash Table for Fast Array Lookup

    11. Doing Something with a Property of an Object

    12. Sorting an Array of Objects

    13. Customizing an Object's Prototype

    14. Converting Arrays and Custom Objects to Strings

  4. Chapter 4 Variables, Functions, and Flow Control

    1. Introduction

    2. Creating a JavaScript Variable

    3. Creating a Named Function

    4. Nesting Named Functions

    5. Creating an Anonymous Function

    6. Delaying a Function Call

    7. Branching Execution Based on Conditions

    8. Handling Script Errors Gracefully

    9. Improving Script Performance

  5. Chapter 5 Browser Feature Detection

    1. Introduction

    2. Detecting the Browser Brand

    3. Detecting an Early Browser Version

    4. Detecting the Internet Explorer Version

    5. Detecting the Netscape Navigator Version

    6. Detecting the Client Operating System

    7. Detecting Object Support

    8. Detecting Object Property and Method Support

    9. Detecting the Browser Written Language

    10. Detecting Cookie Availability

    11. Defining Browser- or Feature-Specific Links

    12. Testing on Multiple Browser Versions

  6. Chapter 6 Managing Browser Windows

    1. Introduction

    2. Setting the Main Window's Size

    3. Positioning the Main Window

    4. Maximizing the Main Window

    5. Creating a New Window

    6. Bringing a Window to the Front

    7. Communicating with a New Window

    8. Communicating Back to the Main Window

    9. Using Internet Explorer Modal/Modeless Windows

    10. Simulating a Cross-Browser Modal Dialog Window

    11. Simulating a Window with Layers

  7. Chapter 7 Managing Multiple Frames

    1. Introduction

    2. Creating a Blank Frame in a New Frameset

    3. Changing the Content of One Frame from Another

    4. Changing the Content of Multiple Frames at Once

    5. Replacing a Frameset with a Single Page

    6. Avoiding Being "Framed" by Another Site

    7. Assuring a Page Loads in its Frameset

    8. Reading a Frame's Dimensions

    9. Resizing Frames

    10. Setting Frameset Specifications Dynamically

  8. Chapter 8 Dynamic Forms

    1. Introduction

    2. Auto-Focusing the First Text Field

    3. Performing Common Text Field Validations

    4. Preventing Form Submission upon Validation Failure

    5. Auto-Focusing an Invalid Text Field Entry

    6. Changing a Form's Action

    7. Blocking Submissions from the Enter Key

    8. Advancing Text Field Focus with the Enter Key

    9. Submitting a Form by an Enter Key Press in Any Text Box

    10. Disabling Form Controls

    11. Hiding and Showing Form Controls

    12. Allowing Only Numbers (or Letters) in a Text Box

    13. Auto-Tabbing for Fixed-Length Text Boxes

    14. Changing select Element Content

    15. Copying Form Data Between Pages

  9. Chapter 9 Managing Events

    1. Introduction

    2. Equalizing the IE and W3C Event Models

    3. Initiating a Process After the Page Loads

    4. Determining the Coordinates of a Click Event

    5. Preventing an Event from Performing Its Default Behavior

    6. Blocking Double Clicks

    7. Determining Which Element Received an Event

    8. Determining Which Mouse Button Was Pressed

    9. Reading Which Character Key Was Typed

    10. Reading Which Noncharacter Key Was Pressed

    11. Determining Which Modifier Keys Were Pressed During an Event

    12. Determining the Element the Cursor Rolled From/To

    13. Synchronizing Sounds to Events

  10. Chapter 10 Page Navigation Techniques

    1. Introduction

    2. Loading a New Page or Anchor

    3. Keeping a Page Out of the Browser History

    4. Using a select Element for Navigation

    5. Passing Data Between Pages Via Cookies

    6. Passing Data Between Pages Via Frames

    7. Passing Data Between Pages Via URLs

    8. Creating a Contextual (Right-Click) Menu

    9. Creating Drop-Down Navigation Menus

    10. Providing Navigation Trail Menus

    11. Creating Expandable Menus

    12. Creating Collapsible XML Menus

  11. Chapter 11 Managing Style Sheets

    1. Introduction

    2. Assigning Style Sheet Rules to an Element Globally

    3. Assigning Style Sheet Rules to a Subgroup of Elements

    4. Assigning Style Sheet Rules to an Individual Element

    5. Importing External Style Sheets

    6. Importing Browser- or Operating System-Specific Style Sheets

    7. Changing Imported Style Sheets After Loading

    8. Enabling/Disabling Style Sheets

    9. Toggling Between Style Sheets for an Element

    10. Overriding a Style Sheet Rule

    11. Turning Arbitrary Content into a Styled Element

    12. Creating Center-Aligned Body Elements

    13. Reading Effective Style Sheet Property Values

    14. Forcing Version 6 Browsers into Standards-Compatibility Mode

  12. Chapter 12 Visual Effects for Stationary Content

    1. Introduction

    2. Precaching Images

    3. Swapping Images (Rollovers)

    4. Changing Text Style Properties

    5. Offering Body Text Size Choices to Users

    6. Creating Custom Link Styles

    7. Changing Page Background Colors and Images

    8. Hiding and Showing Elements

    9. Adjusting Element Transparency

    10. Creating Transition Visual Effects

  13. Chapter 13 Positioning HTML Elements

    1. Introduction

    2. Making an Element Positionable in the Document Space

    3. Connecting a Positioned Element to a Body Element

    4. Controlling Positioning Via a DHTML JavaScript Library

    5. Deciding Between div and span Containers

    6. Adjusting Positioned Element Stacking Order (z-order)

    7. Centering an Element on Top of Another Element

    8. Centering an Element in a Window or Frame

    9. Determining the Location of a Nonpositioned Element

    10. Animating Straight-Line Element Paths

    11. Animating Circular Element Paths

    12. Creating a Draggable Element

    13. Scrolling div Content

    14. Creating a Custom Scrollbar

  14. Chapter 14 Creating Dynamic Content

    1. Introduction

    2. Writing Dynamic Content During Page Loading

    3. Creating New Page Content Dynamically

    4. Including External HTML Content

    5. Embedding XML Data

    6. Embedding Data as JavaScript Objects

    7. Transforming XML Data into HTML Tables

    8. Transforming JavaScript Objects into HTML Tables

    9. Converting an XML Node Tree to JavaScript Objects

    10. Creating a New Element

    11. Creating Text Content for a New Element

    12. Creating Mixed Element and Text Nodes

    13. Inserting and Populating an iframe Element

    14. Getting a Reference to an HTML Element Object

    15. Replacing Portions of Body Content

    16. Removing Body Content

    17. Sorting Dynamic Tables

    18. Walking the Document Node Tree

    19. Capturing Document Content

  15. Chapter 15 Dynamic Content Applications

    1. Introduction

    2. Displaying a Random Aphorism

    3. Converting a User Selection into an Arbitrary Element

    4. Automating the Search-and-Replace of Body Content

    5. Creating a Slide Show

    6. Auto-Scrolling the Page

    7. Greeting Users with Their Time of Day

    8. Displaying the Number of Days Before Christmas

    9. Displaying a Countdown Timer

    10. Creating a Calendar Date Picker

    11. Displaying an Animated Progress Bar

  1. Appendix A Keyboard Event Character Values

  2. Appendix B Keyboard Key Code Values

  3. Appendix C ECMAScript Reserved Keywords

  4. Colophon

View Full Table of Contents
Product Details
Title:
JavaScript & DHTML Cookbook
By:
Danny Goodman
Publisher:
O'Reilly Media
Formats:
  • Print
  • Ebook
  • Safari Books Online
Print Release:
April 2003
Ebook Release:
February 2009
Pages:
544
Print ISBN:
978-0-596-00467-5
| ISBN 10:
0-596-00467-2
Ebook ISBN:
978-0-596-10377-4
| ISBN 10:
0-596-10377-8
Customer Reviews
About the Author
  1. Danny Goodman

    has been writing about personal computers and consumer electronics since the late 1970s. In 2001, he celebrated 20 years as a free lance writer and programmer, having published hundreds of magazine articles, several commercial software products, and three dozen computer books. Through the years, his most popular book titles on HyperCard, AppleScript, JavaScript, and Dynamic HTML have covered programming environments that are both accessible to non-professionals yet powerful enough to engage experts. His JavaScript Bible book is now in its fourth edition. To keep up to date on the needs of web developers for his recent books, Danny is also a programming consultant to some of the industry's top intranet development groups and corporations. His expertise in implementing sensible cross-browser client-side scripting solutions is in high demand and allows him to, in his words, "get code under my fingernails while solving real-world problems." Danny was born in Chicago, Illinois during the Truman Administration. He earned a B.A. and M.A. in Classical Antiquity from the University of Wisconsin, Madison. He moved to California in 1983 and lives in a small San Francisco area coastal community, where he alternates views between computer screens and the Pacific Ocean.

    View Danny Goodman's full profile page.

Colophon

Our look is the result of reader comments, our own experimentation, and feedback from distribution channels. Distinctive covers complement our distinctive approach to technical topics, breathing personality and life into potentially dry subjects. The animal on the cover of the JavaScript and DHTML Cookbook is a howler monkey. Howler monkeys are so named because of the very loud sounds they make, which can be heard up to two miles away. They are considered the loudest landliving animals. They have two hollow hyoid bones that allow them to make the powerful sounds they are known for.

Male howler monkeys are black, and females range from a brown to a light tan color. They have a large neckand a large lower jaw (containing the large hyoid bones), short legs, and a long, prehensile tail. All baby howler monkeys are born with brown fur, but the fur on the males eventually changes to black. These monkeys can grow up to 2 feet in length, and can weight up to 16 pounds. The males are usually significantly larger than the females.

Howlers travel and live in packs of one to three males and two to seven females. There is one dominant male in each group. They spend the majority of their time in trees. Their howling vocalizations are used to marktheir territories as well as to communicate with other packs of monkeys. Their diet consists mostly of leaves, but they also eat fruit and bugs. They are becoming an endangered species due to the shrinking size of the forests in which they live and find food. Mary Brady was the production editor and the copyeditor for the JavaScript and DHTML Cookbook. Brian Sawyer and Sarah Sherman provided quality control. John Bickelhaupt wrote the index.

Ellie Volckhausen designed the cover of this book, based on a series design by Edie Freedman. The cover image is a 19th-century engraving from Cuvier's Animals. Emma Colby produced the cover layout with QuarkXPress 4.1 using Adobe's ITC Garamond font.

David Futato designed the interior layout. This bookwas converted by Joe Wizda to FrameMaker 5.5.6 with a format conversion tool created by Erik Ray, Jason McIntosh, Neil Walls, and Mike Sierra that uses Perl and XML technologies. The text font is Linotype Birka; the heading font is Adobe Myriad Condensed; and the code font is LucasFont's TheSans Mono Condensed. The illustrations that appear in the bookwere produced by Robert Romano and Jessamyn Read using Macromedia FreeHand 9 and Adobe Photoshop 6. This colophon was written by Mary Brady.

  • Book cover of JavaScript & DHTML Cookbook