Synopses & Reviews
Using a cookbook approach, The JavaScript Anthology will show you how to apply JavaScript to solve over 101 common Web Development challenges. You'll discover how-to:
Optimize your code so that it runs fasterCreate Ajax applications with the XmlHttpRequest objectValidate web forms to improve usabilityTake control of your web pages with the DOMEnsure that your JavaScript code is accessibleCreate slick drop-down menu systemsIncluded in this book is extensive coverage of DHTML and Ajax, including how-to create and customize advanced effects such as draggable elements, dynamically sorting data in a Web Browser, advanced menu systems, retrieving data from a Web Server using XMLHttpRequest and more.
The JavaScript Anthology also includes extensive coverage of object oriented coding, efficient script design, accessibility, and cross-browser issues. Best of all, you'll get download access to all the code used in the book, so you can put the scripts to use instantly.
From the Publisher
"Take control with the ultimate JavaScript toolkit"
The JavaScript Anthology: 101 Essential Tips, Tricks & Hacks provides you with tried and tested real-world solutions to over 100 real-world scripting problems.
Among the 101 Tips, Tricks & Hacks you'll learn how-to:
- Search and replace text using regular expressions.
- Navigate the DOM and create, delete, and move elements on the page.
- Validate email addresses on your web forms.
- Print inline error messages when validating forms.
- Minimize the problems associated with popup windows.
- Make a slideshow of images.
- Ensure your code works on different browsers.
- Make a style sheet switcher.
- Build an accessible drop-down menu system.
- Construct drag 'n' drop interfaces using AJAX.
- Use JavaScript and Flash together.
- Make your JavaScript accessible: an in-depth look at minimizing the accessibility problems associated with using JavaScript.
- Use the XMLHttpRequest object to build AJAX applications.
- Optimize your JavaScript code so that it runs faster.
- And much more!
Who Should Read This Book?If you're using JavaScript on your projects right now, and you want to do things faster and better, this book is for you. The JavaScript Anthology will save you the frustration of hunting down code on the Web only to find that it isn't customizable, and doesn't represent best practice or work across different browsers.
The JavaScript Anthology: 101 Essential Tips, Tricks & Hacks contains thoroughly tested, cross-browser code that you can easily modify to suit your own needs.
The book is written in the usual SitePoint style: it's clear and fun to read, with plenty of example code that you can apply immediately to your own web sites. Plus, it's super-easy to navigate the book to find exactly what you want thanks to its cookbook approach and professionally-produced index. It's the perfect reference book.
There's no need to re-type any of the code in the book. As always, customers receive instant download access to all the files used in the book, so you can apply them immediately to your own projects.
Synopsis
Using a cookbook approach, The JavaScript Anthology will show you how to apply JavaScript to solve over 101 common Web Development challenges. You'll discover how-to:
Optimize your code so that it runs faster Create Ajax applications with the XmlHttpRequest object Validate web forms to improve usability Take control of your web pages with the DOM Ensure that your JavaScript code is accessible Create slick drop-down menu systems
Included in this book is extensive coverage of DHTML and Ajax, including how-to create and customize advanced effects such as draggable elements, dynamically sorting data in a Web Browser, advanced menu systems, retrieving data from a Web Server using XMLHttpRequest and more.
The JavaScript Anthology also includes extensive coverage of object oriented coding, efficient script design, accessibility, and cross-browser issues. Best of all, you'll get download access to all the code used in the book, so you can put the scripts to use instantly.
Synopsis
Using a cookbook approach, The "JavaScript Anthology" shows how to apply JavaScript to solve a multitude of common Web Development challenges.
About the Author
Cameron Adams is an author of multiple web development books and is often referred to as a "Web Technologist." In addition to his extensive JavaScript experience, Cameron's passions extend to CSS, PHP, and graphic design.JAMES EDWARDS is a Nortel Networks Certified Support Specialist (NNCSS) in VPN Routers. His experience includes work with some of Nortel's largest enterprise customers.
RICHARD BRAMANTE, also a Nortel Networks Certified Support Specialist (NNCSS), has been in Nortel VPN Router support for three years, and was a technology lead on the Instant Internet.
AL MARTIN is a technical writer with 15 years of experience in electro-mechanical and computer-related disciplines.
Table of Contents
Copyright; James; Cameron; Preface; Who Should Read this Book?; What's in this Book?; The Book's Web Site; The SitePoint Forums; The SitePoint Newsletters; Your Feedback; Acknowledgements; Chapter 1: Getting Started with JavaScript; 1.1 JavaScript Defined; 1.2 JavaScript's Limitations; 1.3 JavaScript Best Practices; 1.4 Providing for Users who Don't Have JavaScript (Progressive Enhancement); 1.5 Separating Content from Behavior (Unobtrusive Scripting); 1.6 Using Braces and Semicolons (Consistent Coding Practice); 1.7 Adding a Script to a Page; 1.8 Getting Multiple Scripts to Work on the Same Page; 1.9 Hiding JavaScript Source Code; 1.10 Debugging a Script; 1.11 Strict Warnings; 1.12 Summary; Chapter 2: Working with Numbers; 2.1 Doing Math with JavaScript; 2.2 Rounding a Number to x Decimal Places; 2.3 Creating and Constraining Random Numbers; 2.4 Converting a Number to a String; 2.5 Formatting Currency Values; 2.6 Converting a String to a Number; 2.7 Converting Numbers to Ordinals (-st, -nd, -rd, -th); 2.8 Summary; Chapter 3: Working with Strings; 3.1 Including a Special Character in a String; 3.2 Transforming the Character Case of a String; 3.3 Encoding a URL; 3.4 Comparing Two Strings; 3.5 Finding a Substring within a String; 3.6 Splitting a String into Substrings; 3.7 Creating a Regular Expression; 3.8 Testing whether a String Matches a Regular Expression; 3.9 Testing whether a String Contains Only Numeric Data; 3.10 Testing whether a String is a Valid Phone Number; 3.11 Testing whether a String is a Valid Email Address; 3.12 Searching and Replacing Text using a Regular Expression; 3.13 Summary; Chapter 4: Working with Arrays; 4.1 Using Array-literals; 4.2 Creating an Array of Arrays; 4.3 Indexing an Array with Strings Instead of Numbers; 4.4 Turning an Array into a String; 4.5 Adding or Removing Members from an Array; 4.6 Sorting an Array into Alphabetical or Numeric Order; 4.7 Sorting a Multi-dimensional Array; 4.8 Sorting an Array Randomly; 4.9 Summary; Chapter 5: Navigating the Document Object Model; 5.1 Accessing Elements; 5.2 Creating Elements and Text Nodes; 5.3 Changing the Type of an Element; 5.4 Removing an Element or Text Node; 5.5 Reading and Writing the Attributes of an Element; 5.6 Getting all Elements with a Particular Attribute Value; 5.7 Adding and Removing Multiple Classes to/from an Element; 5.8 Summary; Chapter 6: Processing and Validating Forms; 6.1 Reading and Writing the Data in a Text Field; 6.2 Reading and Setting the State of a Checkbox; 6.3 Reading and Setting the State of a Radio Button; 6.4 Reading and Setting the Value of a Select Box; 6.5 Validating a Mandatory Text Field; 6.6 Validating a Numeric Field; 6.7 Validating an Email Address Field; 6.8 Checking for Unselected Radio Buttons; 6.9 Stopping a Form Being Submitted Unless all its Fields are Valid; 6.10 Validating a Form with an Unknown Number of Fields; 6.11 Printing Inline Error Messages when Validating a Form; 6.12 Making Form Fields Appear or Disappear, Based on the Value of other Fields; 6.13 Summary; Chapter 7: Working with Windows and Frames; 7.1 Using Popup Windows; 7.2 Opening Off-site Links in a New Window; 7.3 Communicating Between Frames; 7.4 Getting the Scrolling Position; 7.5 Making the Page Scroll to a Particular Position; 7.6 Getting the Viewport Size (the Available Space inside the Window); 7.7 Summary; Chapter 8: Working with Cookies; 8.1 Writing Cookies; 8.2 Reading a Cookie; 8.3 Setting a Cookie to Expire at a Specific Date and Time; 8.4 Making a Cookie Accessible Only from a Specific Domain or Path; 8.5 Circumventing Browser Restrictions on the Number of Cookies you can Use; 8.6 Summary; Chapter 9: Working with Dates and Times; 9.1 Getting the Date and Time; 9.2 Formatting a Date into a Sentence; 9.3 Formatting the Time into a 12- or 24-hour Clock; 9.4 Comparing Two Dates; 9.5 Formatting the Difference Between Dates; 9.6 Summary; Chapter 10: Working with Images; 10.1 Preloading Images; 10.2 Swapping One Image for Another; 10.3 Displaying an Image at Random; 10.4 Making a Slideshow of Several Images; 10.5 Making an Image Fade in or out; 10.6 Making an Image-based Clock that Updates in Real Time; 10.7 Making a Progress Indicator; 10.8 Summary; Chapter 11: Detecting Browser Differences; 11.1 Identifying Support for a Particular Feature; 11.2 Identifying a Particular Browser; 11.3 Detecting Quirks Mode and Standards Mode; 11.4 Summary; Chapter 12: Using JavaScript with CSS; 12.1 Changing the Style of a Single Element; 12.2 Changing the Style of a Group of Elements; 12.3 Retrieving the Computed Style of an Element; 12.4 Making a Style Sheet Switcher; 12.5 Making a Style Sheet Switcher that Handles Multiple Media Types; 12.6 Reading and Modifying an Existing Style Sheet; 12.7 Adding New Style Sheet Rules; 12.8 Deleting a Rule from a Style Sheet; 12.9 Creating a New Style Sheet; 12.10 Summary; Chapter 13: Basic Dynamic HTML; 13.1 Handling Events; 13.2 Finding the Size of an Element; 13.3 Finding the Position of an Element; 13.4 Detecting the Position of the Mouse Cursor; 13.5 Displaying a Tooltip when you Mouse Over an Element; 13.6 Sorting Tables by Column; 13.7 Summary; Chapter 14: Time and Motion; 14.1 Using setTimeout and setInterval; 14.2 Making an Object Move Along a Set Path; 14.3 Making Animation Less Jerky; 14.4 Implementing Drag-and-drop Behavior; 14.5 Reordering a List Using Drag-and-drop Functionality; 14.6 Making a Scrolling News Ticker; 14.7 Creating Clip-based Transition Effects; 14.8 Making a Slider Control; 14.9 Summary; Chapter 15: DHTML Menus and Navigation; 15.1 Making a Drop-down or Fly-out Menu; 15.2 Adding Arrows to Indicate the Presence of a Submenu; 15.3 Adding Timers so the Menus Don't Open and Close so Abruptly; 15.4 Making Sure the Menus Stay Inside the Window; 15.5 Making the Menus Display Over select Elements; 15.6 Making a Folder Tree or Expanding Menu; 15.7 Indicating Expanded Branches in a Menu; 15.8 Allowing Only One Menu Branch to Be Open at Any Time; 15.9 Opening the Current Sub-branch Automatically; 15.10 Summary; Chapter 16: JavaScript and Accessibility; 16.1 Is JavaScript Inaccessible?; 16.2 Making Scripts Accessible to the Keyboard; 16.3 Using Device-independent Event Handlers; 16.4 Making Scripts Accessible to the Keyboard as well as the Mouse; 16.5 Making title Attribute Tooltips Display on Focus; 16.6 Making a DHTML Menu Accessible to the Keyboard; 16.7 Making a DHTML Menu Usable via the Keyboard; 16.8 Making a DHTML Slider Control Accessible to the Keyboard; 16.9 Making Scripts Accessible to Screen Readers; 16.10 Summary; Chapter 17: Using JavaScript with Flash; 17.1 Detecting whether Flash is Installed in a Browser; 17.2 Communicating Between JavaScript and Flash; 17.3 Summary; Chapter 18: Building Web Applications with JavaScript; 18.1 Retrieving Data Using XMLHttpRequest; 18.2 Retrieving Data without Using XMLHttpRequest; 18.3 Creating Custom Dialogs (Such as Popup Forms); 18.4 Creating Editable Elements; 18.5 Controlling Text Selections; 18.6 Creating an Auto-complete Text Field; 18.7 Summary; Chapter 19: Object Orientation in JavaScript; 19.1 What's so Good about Object Orientation?; 19.2 Object Based Code vs Object Oriented Code; 19.3 Writing an Object Oriented Script; 19.4 Creating Methods for an Object; 19.5 Modelling Inheritance; 19.6 Understanding Scope; 19.7 Implementing Namespaces; 19.8 Summary; Chapter 20: Keeping up the Pace; 20.1 Making Scripts Run Faster; 20.2 Writing Scripts Using Less Code; 20.3 Optimizing Scripts for the Web; 20.4 Avoiding Memory Leaks; 20.5 Making Scripts Run Before the Load Event; 20.6 Summary;