JavaScript:Help Desk

From virtualMV2015wiki
Jump to: navigation, search
 Home  JavaScript <

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.
    1. Check for the correct use of : and ; e.g. font-weight; bold; should be font-weight: bold;
    2. 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[1] 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. '<name>' is null or not an object


  • 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)[2]

Browser compatibility

IE 8.0

Leading spaces

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

msg = (""," DisplayWindow","scrollbars =yes, resizable=yes");

works in Firefox but not in IE.

Solution: Remove leading space

msg = ("","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 /> in the first example does not work :(

<input type="button" value="Press Me" onClick=fnDisplayName() > 
<input type="button" value="Press Me" onClick="fnDisplayName()" />

Icon References.png References

  1. JavaScript Try...Catch Statement. In w3Schools. Retrieved from
  2. Tecumseh Group, Inc.(2010) Why do I get a null or not an object error?. Retrieved March 14, 2010 from

JavaScript:Help Desk. (2017). In virtualMV's ( Michael Verhaart ) wiki. Retrieved December 17, 2017, from    (zotero)