Howto get child controls collection in Jscript (withous using object.all)?

M

Mateo

Let's say that I have panel control which is container control, and I need
to access every child control inside panel control from JScript. I have this
line of JS code:


var oCollection = pnlProperties.all;



And then I browse through te collection with for loop doing what I need
etc..





Anyway, this line of code seems to be huge problem for Mozilla browser,
becouse it is not supported by W3C standard (document.all is not
compatibile with standard).





Is there any W3C compatibile method which returns collection of child
controls within parent control? Or somethign that could help me to collect
this collection manually... I failed to find some...





I have 7 algorithms based on this structure so I really have to keep this
collection or change 7 algorithms not to work with this collection..





Thanx!
 
R

Robert

Mateo said:
Let's say that I have panel control which is container control, and I need
to access every child control inside panel control from JScript. I have this
line of JS code:


var oCollection = pnlProperties.all;

var oCollection = pnlProperties.childNodes;

returns a NodeList which you can use to loop
 
M

Mateo

Ok... but...

I have panel control (asp.net web form control) and I have 6 check box and
list
box controls contained inside panel control...

pnlProperties.childNodes return me collection with 2 child controls????
Why....

I tried with non-web form controls (standard HTML controls) and I get the
similar result....
I don't understand this:(
 
R

Robert

Mateo said:
I have panel control (asp.net web form control) and I have 6 check box and
list
box controls contained inside panel control...

pnlProperties.childNodes return me collection with 2 child controls????
Why....

I tried with non-web form controls (standard HTML controls) and I get the
similar result....
I don't understand this:(

Well, I am just guessing, but maybe your .net form controls creates 2
child nodes which are just containers themselves used for layour
purposes. You could check this by viewing your HTML.

So what you probably want is not getting a collection of your child
nodes, but all descendants.
Perhaps getElementsByTagName("input") returns the list that you need.
Or you need to loop the childNodes too when appropriate.
 
M

Mateo

Thx man!



This works...

for exmaple : parentControl.childNodes[0].childNodes[1].id


So I wrote recursive algorithm which walks through tree, and I get complete
collection of child nodes....


Thx 4 giving me idea!
 
M

Martin Honnen

Mateo said:
Let's say that I have panel control which is container control, and I need
to access every child control inside panel control from JScript. I have this
line of JS code:


var oCollection = pnlProperties.all;

The all collection does not only contain the child elements but all
descendant elements thus you would need
var oCollection = pnlProperties.getElementsByTagName('*');
in a W3C DOM compliant script to have the same result.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,434
Messages
2,571,685
Members
48,796
Latest member
Greg L.

Latest Threads

Top