Home arrow JavaScript arrow Page 4 - Debugging in Javascript

Debugging in Javascript

Despite its widespread use, there is little support for debugging in Javascript. When scripts get complicated, the debugging process can cause even the most patient programmer to pull out their hair in frustration. Chris Root offers several tools and techniques that just might keep you from going prematurely bald during the debugging process.

Author Info:
By: Chris Root
Rating: 4 stars4 stars4 stars4 stars4 stars / 26
February 16, 2005
  1. · Debugging in Javascript
  2. · The Hard Way
  3. · Using Comments
  4. · Are We There Yet?
  5. · Make a Log Window

print this article

Debugging in Javascript - Are We There Yet?
(Page 4 of 5 )

Okay now, let's get rid of the comment characters and the alert altogether. What? Still not working? There is one more problem. We have a string to which we are setting our text field value that uses a mix of single and double quotes. This is bad.

<script language="Javascript">
//The Script
function doIt(fName)
   var fObj = document.getElementById(fName);
   if(fObj.value == "")
      fObj.value = 'You're really pushing my buttons!";

Change the single quote to a double one and then try again. It should work just fine. Let's hope that you won't have that many errors in your script, but by walking through it we got to the bottom of errors that otherwise might have taken a long time to find.

One Problem with Alerts

Some browsers (Firefox on OS X for instance) do not allow you to select and copy text from an alert box. This can be useful if a script you are writing generates HTML using DOM methods. This markup will not be visible using the "view source" browser feature. If you display the innerHTML property of a tag in an alert dialog, select it, copy it and paste it into a blank document, you can work with it to fix any problems or try different styles without running the script that generated it each time. If you can't select the text in the alert dialog, then you need another solution.

blog comments powered by Disqus

- Project Nashorn to Make Java, JavaScript Wor...
- JavaScript Virus Attacks Tumblr Blogs
- Google Releases Stable Dart Version, JavaScr...
- Khan Academy Unveils New JavaScript Learning...
- Accessing Nitro? There`s an App for That
- JQuery 2.0 Leaving Older IE Versions Behind
- Fastest JavaScript Engine Might Surprise You
- Microsoft Adjusting Chakra for IE 10
- Brendan Eich: We Don`t Need Google Native Cl...
- An Overview of JavaScript Statements
- An Overview of JavaScript Operators
- Overview of JavaScript Variables
- More of the Top jQuery Social Plugins
- The Top jQuery Social Plugins
- More of the Top jQuery Slider Plugins

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials