• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3130
  • Last Modified:

How to print out variables in Javascript for debugging

Hi,
I'm pretty new to Javascript but I do have a programming background.
I have a script from a book (on Ajax) that doesn't work, which isn't much of a surprise since half the scripts in this books source code don't work (Ajax for Dummies).

Anyway, I'm printing out variables using an alert statement but when I get to the statement below the message I get back is "[objectHTMLCollection]".  Can someone tell me how I can print out the contents of that object?

-- Snip --
options = xmlDocument.getElementsByTagName("option");
alert(options);
---


Thanks!

M
0
michaelshavel
Asked:
michaelshavel
  • 2
2 Solutions
 
hieloCommented:
var options = xmlDocument.getElementsByTagName("option");
if(options)
{
      for(var i=0,limit=options.length; i < limit; ++i)
      alert(options[i]);
}
0
 
b0lsc0ttIT ManagerCommented:
michaelshavel,

If you want just one alert then try ...

if(options) alert(options.join("\n"));

I kept Hielo's if there since that will probably help this script.  Credit to him for that suggestion.  Mine is just a little different since it puts the array in a string separated by a new line.

Let me know if you have any questions or need more information.

b0lsc0tt
0
 
michaelshavelAuthor Commented:
Thank you both!
0
 
b0lsc0ttIT ManagerCommented:
Your welcome!  I'm glad I could assist.  Thanks for the grade, the points and the fun question.

bol
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now