JavaScript:Help Desk

Syntax errors

 * 1) Case. Check your variables (e.g. strName is not the same as strname)
 * 2) JavaScript words misspelt: e.g. fuction rather than function . This may give you a semi-colon missing error.
 * 3) Variable names: Cannot have a space in them (indeed try to eliminate spaces in any names and use CamelCase where possible).
 * 4) Arrays. an array must be declared first before you can assign values. e.g. var arrX = new array; arrX[0]=1;
 * 5) CSS.
 * 6) Check for the correct use of : and ; e.g. font-weight; bold; should be font-weight: bold;
 * 7) Check for any stray quotes - give really unpredictable results :(

You can use the JavaScript try ..catch to trap errors so that your user doesn't get broken pages. However, correct JavaScript code is better. See the JavaScript Try...Catch Statement page for more information Internet Explorer show a JS error with a small error icon at the bottom left of the browser. Click on the icon and the error message is displayed

Semantic (meaning) errors
1. In nested statements check semicolons

2. getElementByID .. is null

The problem may be that the element must be rendered before it is called. So if you want to change the value of an element with id ="x" the tag with id must be created first before the JavaScript is run.

3. ' ' is null or not an object

Solutions:
 * Very carefully check the object name is the same. E.g. if you have cut n pasted from a web example is the form name the same as the one you have used !
 * Tecumseh Group, Inc.(2010)

Leading spaces
Problem: It appears that IE doen't strip out leading spaces in arguments so

msg = window.open (""," DisplayWindow","scrollbars =yes, resizable=yes");

works in Firefox but not in IE.

Solution: Remove leading space

msg = window.open ("","DisplayWindow","scrollbars =yes, resizable=yes");

Mandatory Quotes
It appears that IE 8.0 requires the onClick functions to be in quotes if you terminate the input box with a /

i.e. both work (but the second is more standards compliant (but a /&gt; in the first example does not work :(

