Getting Elements and Contents of a subset of the Document

M

marc

Dear Sirs,

Any idea how I can work this out.?

In my document I have a table row with an unknown number and type of
elements.
I want to make a set of name-value pairs contained in this table row,
while I do not know the names of the elements in advance.

Is there something like "give me all children of this table row"?
Can I get all children in the document with a wildcard 'Subname*', like
give me all elements starting with 'Subname' ?

It's for an Intranet so the browsers could only be IE 6.

Marc Wentink
 
M

Martin Honnen

marc said:
In my document I have a table row with an unknown number and type of
elements.

A HTML table row, a tr element? The number of child elements can be
unknown but the type of child elements can only be td or th.
And a table row element objects has a cells collection that allows you
to access the cells, whether they are td or th elements.

Is there something like "give me all children of this table row"?

Children should be th or td elements accessible in the cells collection.
 
R

RobG

marc said on 13/04/2006 1:48 AM AEST:
Dear Sirs,

Any idea how I can work this out.?

In my document I have a table row with an unknown number and type of
elements.
I want to make a set of name-value pairs contained in this table row,
while I do not know the names of the elements in advance.

Is there something like "give me all children of this table row"?
Can I get all children in the document with a wildcard 'Subname*', like
give me all elements starting with 'Subname' ?

Further to Martin's response, you can also use:

var allDecendents = trRef.getElementsByTagName('*');


Then sift through all the elements. But that seems rather a strange way
to go about it, as the returned collection will have had nearly all the
document structure removed.

It's for an Intranet so the browsers could only be IE 6.

getElmenetsByTagName() is almost fully supported by IE 5.x, if the
parameter is '*' IE5.x will always return an empty collection. IE4
doesn't support getElementsByTagName at all.
 
M

marc

Martin:
Children should be th or td elements accessible in the cells collection.

That would be? The childNodes property of the TR element, right? I
am/was missing the right name of such a propery and then it's difficult
to find information. I am not really that experienced in Javascript I
would know the name of such a property or function.

Thanks a lot for the hint. Marc Wentink
 
H

Hal Rosser

marc said:
Dear Sirs,

Any idea how I can work this out.?

In my document I have a table row with an unknown number and type of
elements.
I want to make a set of name-value pairs contained in this table row,
while I do not know the names of the elements in advance.

Is there something like "give me all children of this table row"?
Can I get all children in the document with a wildcard 'Subname*', like
give me all elements starting with 'Subname' ?

Seems easier to replace the entire *table* or *tr* contents with the new
values.
Build the string consisting of all the tr and td tags and their contents -
and use that string to replace the innerHTML of the table element. - OR
replace all the innerHTML of the <tr> element.
whatchathink? ( my 2¢)
Hal
 
M

marc

Hal:
Seems easier to replace the entire *table* or *tr* contents with the new
values.

No, that is not what I want.

I want to get a few values in the form, send them to the CGI server,
and save some data, in between, without submitting the whole form. And
also without rewriting the whole HTML on the client side. Apart from
saving some data on the server database, the rest of the HMTL page on
the client side does not even change, hence I do not want to redraw
this screen, hence I do not want any new values in that table.
 
M

marc

Rob:
Further to Martin's response, you can also use:
var allDecendents = trRef.getElementsByTagName('*');

Then sift through all the elements. But that seems rather a strange way
to go about it, as the returned collection will have had nearly all the
document structure removed.

Actually that is perfect since I do not care about the document
structure, I just want a non submit call to the server to save some
data, while the whole html table does not change at all. The id of the
data is in the cell name, and it does not matter where in the html
table it appears.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top