Developing and debugging scripts
JavaScript code runs when browser events occur typically in response to something that the user does (for example, clicks a button). Developers should test all the scripts by exercising all the functionality of the application. Sometimes the result of a script is obvious because something moves or changes color. Sometimes nothing obvious happens or perhaps an unexpected page not found error is displayed. Scripts can fail without displaying error messages or any other indication of failure, and the developer is left wondering where to start troubleshooting.
In addition to inserting JavaScript alert function calls into suspect scripts and viewing the page source in the browser, here are two general techniques that can help during script development.
Use browser debugging tools
Get to know your browsers' developer tools and other options. For example, IE displays a warning icon (and sometimes a message) in the lower left-hand corner of the browser window. Click...