VirtualMV/JavaScript/HelpDesk

Debugging techniques

 * In Internet Explorer press [F12] to bring up the dubug window. Click on the script tag and you can see both the code and error displayed.

Syntax errors

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

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)

4. Form does not work but no errors (or error doesn't make sense) Solutions
 * Field name in a form or variable name already used. (Happens when you copy code)

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 :(

