Skip to main content

JavaScript in 10 Simple Steps or Less

JavaScript in 10 Simple Steps or Less

Arman Danesh

ISBN: 978-0-764-54241-1

Dec 2003

648 pages

Select type: Paperback

Product not available for purchase


If you are looking to add exciting interactivity to Web pages and need a quick and easy understanding of the technology in order to do so, then this book is for you-whether you're new to JavaScript or you need a refresher on every-thing from validating user input forms to creating menu trees. Open the book and you'll discover clear, easy-to-follow instructions for more than 250 key JavaScript tasks, each presented in ten quick steps-or less. Easy-to-navigate pages, lots of screen shots, and to-the-point directions guide you through every common (and not so common) JavaScript challenge-and help you get more done in less time.
* Each solution is ten steps-or less-to help you get the job done fast
* Self-contained two-page spreads deliver the answers you need-without flipping pages
* A no-fluff approach focuses on helping you achieve results
* A resource packed with useful and fun ways to get the most out of JavaScript
* Make it simple and get productive fast!- download ready-to-use source code for each task from the book's companion Web site

Related Resources


Contact your Rep for all inquiries


About the Author.



Part 1: JavaScript Basics.

Task 1: Creating a scriptBlock.

Task 2: Hiding Your JavaScript Code.

Task 3: Providing Alternatives to Your JavaScript Code.

Task 4: Including Outside Source Code.

Task 5: Commenting Your Scripts.

Task 6: Writing a JavaScript Command.

Task 7: Temporarily Removing a Command from a Script.

Task 8: Using Curly Brackets.

Task 9: Writing Output to the Browser.

Task 10: Creating a Variable.

Task 11: Outputting a Variable.

Task 12: Creating a String.

Task 13: Creating a Numeric Variable.

Task 14: Performing Math.

Task 15: Concatenating Strings.

Task 16: Searching for Text in Strings.

Task 17: Replacing Text in Strings.

Task 18: Formatting Strings.

Task 19: Applying Multiple Formatting Functions to a String.

Task 20: Creating Arrays.

Task 21: Populating an Array.

Task 22: Sorting an Array.

Task 23: Splitting a String at a Delimiter.

Task 24: Calling Functions.

Task 25: Alerting the User.

Task 26: Confirming with the User.

Task 27: Creating Your Own Functions.

Task 28: Passing an Argument to Your Functions.

Task 29: Returning Values from Your Functions.

Task 30: Passing Multiple Parameters to Your Functions.

Task 31: Calling Functions from Tags.

Task 32: Calling Your JavaScript Code after the Page Has Loaded.

Task 33: Using forLoops.

Task 34: Testing Conditions with if.

Task 35: Using Short-Form Condition Testing.

Task 36: Looping on a Condition.

Task 37: Looping through an Array.

Task 38: Scheduling a Function for Future Execution.

Task 39: Scheduling a Function for Recurring Execution.

Task 40: Canceling a Scheduled Function.

Task 41: Adding Multiple Scripts to a Page.

Task 42: Calling Your JavaScript Code after the Page Has Loaded.

Task 43: Check If Java Is Enabled with JavaScript.

Part 2: Outputting to the Browser.

Task 44: Accessing the documentObject.

Task 45: Outputting Dynamic HTML.

Task 46: Including New Lines in Output.

Task 47: Outputting the Date to the Browser.

Task 48: Outputting the Date and Time in a Selected Time Zone.

Task 49: Controlling the Format of Date Output.

Task 50: Customizing Output by the Time of Day.

Task 51: Generating a Monthly Calendar.

Task 52: Customizing Output Using URL Variables.

Task 53: Dynamically Generating a Menu.

Task 54: Replacing the Browser Document with a New Document.

Task 55: Redirecting the User to a New Page.

Task 56: Creating a “Page Loading ...” Placeholder.

Part 3: Images and Rollovers.

Task 57: Accessing an HTML-Embedded Image in JavaScript.

Task 58: Loading an Image Using JavaScript.

Task 59: Detecting MouseOver Events on Images.

Task 60: Detecting Click Events on Images.

Task 61: Switching an Image Programatically.

Task 62: Using Multiple Rollovers in One Page.

Task 63: Displaying a Random Image.

Task 64: Displaying Multiple Random Images.

Task 65: Using a Function to Create a Rollover.

Task 66: Using a Function to Trigger a Rollover.

Task 67: Using Functions to Create Multiple Rollovers in One Page.

Task 68: Creating a Simple Rollover Menu System.

Task 69: Creating a Slide Show in JavaScript.

Task 70: Randomizing Your Slide Show.

Task 71: Triggering Slide Show Transitions from Links.

Task 72: Including Captions in a Slide Show.

Task 73: Testing If an Image Is Loaded.

Task 74: Triggering a Rollover in a Different Location with a Link.

Task 75: Using Image Maps and Rollovers Together.

Task 76: Generating Animated Banners in JavaScript.

Task 77: Displaying a Random Banner Ad.

Part 4: Working with Forms.

Task 78: Preparing Your Forms for JavaScript.

Task 79: Accessing Text Field Contents.

Task 80: Dynamically Updating Text Fields.

Task 81: Detecting Changes in Text Fields.

Task 82: Accessing Selection Lists.

Task 83: Programmatically Populating a Selection List.

Task 84: Dynamically Changing Selection List Content.

Task 85: Detecting Selections in Selection Lists.

Task 86: Updating One Selection List Based on Selection in Another.

Task 87: Using Radio Buttons instead of Selection Lists.

Task 88: Detecting the Selected Radio Button.

Task 89: Detecting Change of Radio Button Selection.

Task 90: Updating or Changing Radio Button Selection.

Task 91: Creating Check Boxes.

Task 92: Detecting Check Box Selections.

Task 93: Changing Check Box Selections.

Task 94: Detecting Changes in Check Box Selections.

Task 95: Verifying Form Fields in JavaScript.

Task 96: Using the onSubmit Attribute of the Form Tag to Verify Form Fields.

Task 97: Verifying Form Fields Using INPUT TYPE=”button” Instead of TYPE=”submit”.

Task 98: Validating E-mail Addresses.

Task 99: Validating Zip Codes.

Task 100: Validating Phone Numbers.

Task 101: Validating Credit Card Numbers.

Task 102: Validating Selection List Choices.

Task 103: Validating Radio Button Selections.

Task 104: Validating Check Box Selections.

Task 105: Validating Passwords.

Task 106: Validating Phone Numbers with Regular Expressions.

Task 107: Creating Multiple Form Submission Buttons Using INPUT TYPE=”button” uttons.

Task 108: Reacting to Mouse Clicks on Buttons.

Task 109: Using Graphical Buttons in JavaScript.

Task 110: Controlling the Form Submission URL.

Task 111: Validating a Numeric Text Field with Regular Expressions.

Task 112: Encrypting Data before Submitting It.

Task 113: Using Forms for Automatic Navigation Jumping.

Part 5: Manipulating Browser Windows.

Task 114: Using the WindowObject.

Task 115: Popping Up an Alert Dialog Box.

Task 116: Popping Up Confirmation Dialog Boxes.

Task 117: Popping Up JavaScript Prompts.

Task 118: Creating New Browser Windows.

Task 119: Opening a New Browser Window from a Link.

Task 120: Setting the Size of New Browser Windows.

Task 121: Setting the Location of New Browser Windows.

Task 122: Controlling Toolbar Visibility for New Browser Windows.

Task 123: Determining the Availability of Scroll Bars for New Browser Windows.

Task 124: Restricting Resizing of New Browser Windows.

Task 125: Loading a New Document into a Browser Window.

Task 126: Controlling Window Scrolling from JavaScript.

Task 127: Opening a Full-Screen Window in Internet Explorer.

Task 128: Handling the Parent-Child Relationship of Windows.

Task 129: Updating One Window’s Contents from Another.

Task 130: Accessing a Form in Another Browser Window.

Task 131: Closing a Window in JavaScript.

Task 132: Closing a Window from a Link.

Task 133: Creating Dependent Windows in Netscape.

Task 134: Sizing a Window to Its Contents in Netscape.

Task 135: Loading Pages into Frames.

Task 136: Updating One Frame from Another Frame.

Task 137: Sharing JavaScript Code between Frames.

Task 138: Using Frames to Store Pseudo-Persistent Data.

Task 139: Using One Frame for Your Main JavaScript Code.

Task 140: Using a Hidden Frame for Your JavaScript Code.

Task 141: Working with Nested Frames.

Task 142: Updating Multiple Frames from a Link.

Task 143: Dynamically Creating Frames in JavaScript.

Task 144: Dynamically Updating Frame Content.

Task 145: Referring to Unnamed Frames Numerically.

Part 6: Manipulating Cookies.

Task 146: Creating a Cookie in JavaScript.

Task 147: Accessing a Cookie in JavaScript.

Task 148: Displaying a Cookie.

Task 149: Controlling the Expiry of a Cookie.

Task 150: Using a Cookie to Track a User’s Session.

Task 151: Using a Cookie to Count Page Access.

Task 152: Deleting a Cookie.

Task 153: Creating Multiple Cookies.

Task 154: Accessing Multiple Cookies.

Task 155: Using Cookies to Present a Different Home Page for New Visitors.

Task 156: Creating a Cookie Function Library.

Task 157: Allowing a Cookie to be Seen for all Pages in a Site.

Part 7: DHTML and Style Sheets.

Task 158: Controlling Line Spacing.

Task 159: Determining an Object’s Location.

Task 160: Placing an Object.

Task 161: Moving an Object Horizontally.

Task 162: Moving an Object Vertically.

Task 163: Moving an Object Diagonally.

Task 164: Controlling Object Movement with Buttons.

Task 165: Creating the Appearance of Three-Dimensional Movement.

Task 166: Centering an Object Vertically.

Task 167: Centering an Object Horizontally.

Task 168: Controlling Line Height in CSS.

Task 169: Creating Drop Shadows with CSS.

Task 170: Modifying a Drop Shadow.

Task 171: Removing a Drop Shadow.

Task 172: Placing a Shadow on a Nonstandard Corner.

Task 173: Managing Z-Indexes in JavaScript.

Task 174: Setting Fonts for Text with CSS.

Task 175: Setting Font Style for Text with CSS.

Task 176: Controlling Text Alignment with CSS.

Task 177: Controlling Spacing with CSS.

Task 178: Controlling Absolute Placement with CSS.

Task 179: Controlling Relative Placement with CSS.

Task 180: Adjusting Margins with CSS.

Task 181: Applying Inline Styles.

Task 182: Using Document Style Sheets.

Task 183: Creating Global Style Sheet Files.

Task 184: Overriding Global Style Sheets for Local Instances.

Task 185: Creating a Drop Cap with Style Sheets.

Task 186: Customizing the Appearance of the First Line of Text.

Task 187: Applying a Special Style to the First Line of Every Element on the Page.

Task 188: Applying a Special Style to All Links.

Task 189: Accessing Style Sheet Settings.

Task 190: Manipulating Style Sheet Settings.

Task 191: Hiding an Object in JavaScript.

Task 192: Displaying an Object in JavaScript.

Task 193: Detecting the Window Size.

Task 194: Forcing Capitalization with Style Sheet Settings.

Task 195: Detecting the Number of Colors.

Task 196: Adjusting Padding with CSS.

Part 8: Dynamic User Interaction.

Task 197: Creating a Simple Pull-Down Menu.

Task 198: Creating Two Pull-Down Menus.

Task 199: Detecting and Reacting to Selections in a Pull-Down Menu.

Task 200: Generating a Drop-Down Menu with a Function.

Task 201: Placing Menu Code in an External File.

Task 202: Inserting a Prebuilt Drop-Down Menu.

Task 203: Creating a Floating Window.

Task 204: Closing a Floating Window.

Task 205: Resizing a Floating Window.

Task 206: Moving a Floating Window.

Task 207: Changing the Content of a Floating Window.

Task 208: Detecting Drag and Drop.

Task 209: Moving a Dragged Object in Drag and Drop.

Task 210: Changing Cursor Styles.

Task 211: Determining the Current Scroll Position.

Task 212: Creating an Expanding/Collapsing Menu.

Task 213: Creating a Highlighting Menu Using Just Text and CSS—No JavaScript.

Task 214: Creating a Highlighting Menu Using Text, CSS, and JavaScript.

Task 215: Placing Content Offscreen.

Task 216: Sliding Content into View.

Task 217: Creating a Sliding Menu.

Task 218: Auto-Scrolling a Page.

Part 9: Handling Events.

Task 219: Responding to the onMouseOverEvent.

Task 220: Taking Action When the User Clicks on an Object.

Task 221: Responding to Changes in a Form’s Text Field.

Task 222: Responding to a Form Field Gaining Focus with onFocus.

Task 223: Taking Action When a Form Field Loses Focus with onBlur.

Task 224: Post-Processing Form Data with onSubmit.

Task 225: Creating Code to Load When a Page Loads with onLoad.

Task 226: Executing Code When a User Leaves a Page for Another.

Task 227: Taking Action When a User Makes a Selection in a Selection List.

Part 10: Bookmarklets.

Task 228: Downloading and Installing Bookmarklets.

Task 229: Checking Page Freshness with a Bookmarklet.

Task 230: Checking for E-mail Links with a Bookmarklet.

Task 231: E-mailing Selected Text with a Bookmarklet in Internet Explorer.

Task 232: E-mailing Selected Text with a Bookmarklet in Netscape.

Task 233: Displaying Images from a Page with a Bookmarklet.

Task 234: Changing Background Color with a Bookmarklet.

Task 235: Removing Background Images with a Bookmarklet.

Task 236: Hiding Images with a Bookmarklet.

Task 237: Hiding Banners with a Bookmarklet.

Task 238: Opening All Links in a New Window with a Bookmarklet.

Task 239: Changing Page Fonts with a Bookmarklet.

Task 240: Highlighting Page Links with a Bookmarklet.

Task 241: Checking the Current Date and Time with a Bookmarklet.

Task 242: Checking Your IP Address with a Bookmarklet.

Task 243: Searching Yahoo! with a Bookmarklet in Internet Explorer.

Task 244: Searching Yahoo! with a Bookmarklet in Netscape.

Part 11: Cross-Browser Compatibility and Issues.

Task 245: Detecting the Browser Type.

Task 246: Detecting the Browser Version.

Task 247: Browser Detection Using Object Testing.

Task 248: Creating Browser Detection Variables.

Task 249: Dealing with Differences in Object Placement in Newer Browsers.

Task 250: Creating Layers with the div Tag.

Task 251: Controlling Layer Placement in HTML.

Task 252: Controlling Layer Size in HTML.

Task 253: Controlling Layer Visibility in HTML.

Task 254: Controlling Layer Ordering in HTML.

Task 255: Changing Layer Placement and Size in JavaScript.

Task 256: Changing Layer Visibility in JavaScript.

Task 257: Changing Layer Ordering in JavaScript.

Task 258: Fading Objects.

Task 259: Creating a Page Transition in Internet Explorer.

Task 260: Installing the X Cross-Browser Compatibility Library.

Task 261: Showing and Hiding Elements with X.

Task 262: Controlling Stacking Order with X.

Task 263: Changing Text Color with X.

Task 264: Setting a Background Color with X.

Task 265: Setting a Background Image with X.

Task 266: Repositioning an Element with X.

Task 267: Sliding an Element with X.

Task 268: Changing Layer Sizes with X.

Appendix A: JavaScript Quick Reference.

Appendix B: CSS Quick Reference.


Download the sample code

Welcome to the companion web site

Welcome to the companion web site. All the code from the book is available for download. You will need a program capable of opening ZIP format archives in order to open the file. You can download one at or The sample code is available on the download page.

View all in 10 Simple Steps or Less

View all in 10 Simple Steps or Less titles by Wiley.