Craft > JavaScript Tips

SwansonSoftware Home | Site Index | View With Frames

Draft Version 1.7, January 30 2004

Contents

  1. Introduction
  2. Debugging Javascript
  3. Browser and Client Capabilities
  4. Dynamic Effects That Work In Most Browsers
  5. Dynamic Effects That Work in IE only
  6. Validation
  7. Links to More Information
  8. References

Introduction

Next | Top of page

This document is not a tutorial, it presents techniques for handling problems that come up when writing javascript in Web development. Keep in mind that users can turn off Javascript in the options settings of their browsers. Note that the examples described here assume you have javascript enabled.

Whenever a page uses javascript for navigation or functionality that is required for viewing the site, be sure to include a check that javascript is enabled and provide a way to view the site if it is not. To determine if javascript is enabled, use the <noscript></noscript> element.

Whatever you put in the element will appear only when javascript is disabled. SwansonSoftware uses this technique and displays alternative navigation with no frames.


Debugging Javascript

Next | Previous | Top of page

Javascript is notoriously aggravating to debug. If your development environment is a text editor with no facilities for stepping through code and viewing variables, you can spend lots of time hunting down bugs.

These examples show techniques for writing values to a debug window and displaying extended error information. ErrorOut displays the page that an error is on - very helpful if you are using frames because the default error dialog does not indicate which page an error is on.



Browser and Client Capabilities

Next | Previous | Top of page



Dynamic Effects That Work In Most Browsers

Next | Previous | Top of page

Be sure that you use the right event model when using javascript to handle events. For example, Internet Explorer and Opera recognize event.keyCode when dealing with keyboard events, and Netscape recognizes event.which.

  1. Controls on Forms
  2. DIV
  3. IMG
  4. Navigation
  5. SELECT


Dynamic Effects That Work in IE only

Next | Previous | Top of page

Internet Explorer's more recent versions have capabilities that allow you to write applications for business, in less time and for less money than it takes writing for other browsers. We are talking about corporate intranet applications, which require functionality like a table DOM that allows you to create tables dynamically and sort them without hitting the server - with full control over the height and width of each cell; styles that allow you to scroll data in a div element when the data does not fit in the window, and that allows you to highlight rows as the mouse pointer moves over them; styles that allow you to draw text at different angles, e.g. along the axis of a chart.

This is a short list and it already points out the futility of supporting various browsers when you are writing business applications. Maybe you don't like it, but I'm not trying to say which browser is best, just that it's not practical to try to make some kinds of applications work in browsers other than Internet Explorer.

Now that browser makers are improving their support of standards, the day is comming when it will be practical to create non-trivial Web-based applications that don't rely on Java and that work in various browsers, maybe even on various operating systems.

So here are some Internet Explorer-only capabilities.



Validation

Next | Previous | Top of page

If you can find a copy of Eric Krock's FormChek.js at Netscape Communications Corporation, you will find validation functions for everything. You could include the file when you need to validate input, but it is 60k - a bit large if you just want to validate an email address. However you can use the code as the basis for a smaller set of validation functions. In fact, the comments in FormChek.js recommend that you strip out comments and functions that you do not need.



Links to More Information

Next | Previous | Top of page

Reference

Name Rating Description
ECMA Best ECMA Website
Reference Best ECMA - Page with link to the Adobe pdf file
MS Web Best * Microsoft script technologies references

Tutorials

Name Rating Description
W3Schools Good Tutorials and test. Comprehensive list of tutorials on web development technologies.
PT N/A ProgrammingTutorials.com - Links to tutorials in many languages. Lots of links but some are broken; links that are not broken are not always useful.

Free Code

Name Rating Description
JS Source Good The JavaScript Source
Dynamic Drive   DHTML code library. Comprehensive DHTML code library featuring scripts and compontents.

* IE - specific



References


Flanagan, David, 1998, JavaScript, The Definitive Guide, Third Edition: O'Reilly & Associates, Inc., 776 pages. ISBN 1-56592-392-8
Ideas for most of the examples on this page were inspired from this book.

Section on validation uses code from FormChek.js, created 18 Feb 97 by Eric Krock and (c) 1997 Netscape Communications Corporation.


Top of page | Previous