Troubleshooting
There will be times when your code does not do what you expect as a result of syntactical errors or logical errors in your program. Also, browser incompatibility is a particular problem with Javascript. There are several approaches to help you diagnose and fix these sorts of problems.
Javascript Debugger
Both Internet Explorer and Netscape/Mozilla can display messages that provide more information related to script errors.
- In the Internet Options dialog of Internet Explorer, click the Advanced Tab, and make sure that Disable Script Debugging is NOT checked. When you view a page in IE with a Javascript error, a dialog box appears that enables you to see the details of the error.
- Netscape has a more detailed debugger. Just type javascript: in the address bar of Netscape and that will open the Javascript console, which displays Javascript errors.
These debugging techniques in IE and Netscape are helpful in identifying syntactical errors. Sometimes your Javascript code will have logical errors; the code executes, but does not do what you want it to do. In many cases you can diagnose these problems by using a window.alert method to display the value of variables at certain points in your program. For example, use the following code to display the value of the variable x in your code:
var x = 10;
window.alert(x);
You can run the script and Javascript will display an alert box with the value of the x.
|