Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / September 2007

Tip: Looking for answers? Try searching our database.

Walking the Child nodes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tshad - 07 Sep 2007 01:59 GMT
I am trying to walk the Child nodes and am using the code:

  var nodes = document.forms[0].childNodes;
 alert("nodes = " + nodes + "   nodes.length = " + nodes.length);
  for (var i=0; i < nodes.length; ++i)
  {
      alert("Inside for loop - i = " + i);
      alert("id: = " + nodes.id);
      alert("tag: " + node[i].tagName);
  }
alert("length = " + document.addForm.length);

From the first alert I get:

nodes = [object]   nodes.length = 16

From the second alert I get:

Inside for loop - i = 0

From the 3rd alert I get:

id: = undefined

It goes no farther from here because the id is undefined.

Why is that?

What I am trying to do is find out the tag names and types as well ids
(haven't got the type there yet).

If I tak out the alert("tag... out I will get all the nodes as undefined.

What am I doing wrong here?

Thanks,

Tom
bruce barker - 07 Sep 2007 06:12 GMT
try spelling nodes correct and using indexer:

    var nodes = document.forms[0].childNodes;
    for (var i=0; i < nodes.length; ++i)
    {
        alert("Inside for loop - i = " + i);
        alert("id: = " + nodes[i].id);
        alert("tag: " + nodes[i].tagName);
    }

note: id may not be defined if one doesn't exist. you can nodeName in
place of tagName. this will only give immediate childNodes.

-- bruce (sqlwork.com)

> I am trying to walk the Child nodes and am using the code:
>
[quoted text clipped - 34 lines]
>
> Tom
tshad - 10 Sep 2007 16:42 GMT
> try spelling nodes correct and using indexer:
>
[quoted text clipped - 8 lines]
> note: id may not be defined if one doesn't exist. you can nodeName in
> place of tagName. this will only give immediate childNodes.

That fixed it.

What do you mean by "immediate" childNodes?

Thanks,

Tom

> -- bruce (sqlwork.com)
>
[quoted text clipped - 36 lines]
>>
>> Tom
Kevin Spencer - 07 Sep 2007 12:32 GMT
Depending on which browser you're using, text nodes may be identified as
nodes (Mozilla), or not (IE). So, you will have some nodes that indeed have
no id assigned.

Signature

HTH,

Kevin Spencer
Microsoft MVP

DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

>I am trying to walk the Child nodes and am using the code:
>
[quoted text clipped - 34 lines]
>
> Tom

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.