VirtualMV/JavaScript/HelpDesk

From WikiEducator
Jump to: navigation, search




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

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

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)

Browser compatibility

IE 8.0

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

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

VmvIcon References.png References

  1. JavaScript Try...Catch Statement. In w3Schools. Retrieved from http://www.w3schools.com/js/js_try_catch.asp
  2. Tecumseh Group, Inc.(2010) Why do I get a null or not an object error?. Retrieved March 14, 2010 from http://www.tek-tips.com/faqs.cfm?fid=3046

virtualMV  |  Superquick wiki guide  |  Please give me some feedback

VirtualMV/JavaScript/HelpDesk. (2024). In WikiEducator/VirtualMV wiki. Retrieved November 5, 2024, from http:https://wikieducator.org/VirtualMV/JavaScript/HelpDesk    (zotero)