table with no IDs

  • Thread starter bradley_d_watkins
  • Start date
B

bradley_d_watkins

Hey,

Just have a quick question....

Is there any way of accessing the tables appearing on a web-page that
would return an array of their ID's in an array type form?
I have to hide some of their rows, but dont know what their ID's are!!

The problem is that i have to access a dynamically changing web page
and have to know the tables ID's. However the trick comes in when none
of the tables were given ID's.

So i thought that maybe there is some sort of "call" i could make that
would return an array of all the tables "IDs"......

Cheers
 
D

David Dorward

Is there any way of accessing the tables appearing on a web-page that
would return an array of their ID's in an array type form?
I have to hide some of their rows, but dont know what their ID's are!!

document.getElementsByTagName('table') will return a collection of HTML
elements. No need to deal with ids.
The problem is that i have to access a dynamically changing web page
and have to know the tables ID's. However the trick comes in when none
of the tables were given ID's.

You can't get an id from an element that doesn't have an id.
 
B

bradley_d_watkins

Hi

The following worked, however it only returns the first table object on
the webpage. The problem occurs when I need to access subsequent
tables....
document.getElementsByTagName('table') will return a collection of HTML
elements. No need to deal with ids.

Thanks a lot
Brad
 
D

David Dorward

The following worked, however it only returns the first table object on
the webpage. The problem occurs when I need to access subsequent
tables....

That will return a collection. There is probably something wrong with
the way you are accessing it, or the markup. Since you've shown neither
its hard to say what.
 
B

bradley_d_watkins

Hi,

This is what can be seen from 'view source'. Currently Im trying to
gain access to the second table, but no ID was given to it when it was
created...
I have tried this:
var mytables = document.getElementsByTagName('table')
alert(mytables[0].rows[1].innerHTML)

var mytables2 = document.getElementsByTagName('table').item(1)
alert(mytables2.rows[1].innerHTML)

The first one alert returns the first table, but the second alert gives
an error....

.....

<table cellspacing=0 cellpadding=0>
<tr>
<td nowrap colspan=5 bgcolor=black><img src=/images/wi/nothing.gif
height=1></td>
</tr>
<tr>
<td colspan=5 bgcolor=><img src=/images/bars/silver.gif width=74
height=10></td>
</tr>
<tr>
<td nowrap colspan=5 bgcolor=black><img src=/images/wi/nothing.gif
height=1></td>
</tr>
<tr>
<td width=40><font face="verdana" size="-2">0%</font></td>
<td width=20 align=center><font face="verdana"
size="-2">25%</font></td>
<td width=80 align=center><font face="verdana"
size="-2">50%</font></td>
<td width=20 align=center><font face="verdana"
size="-2">75%</font></td>
<td width=40 align=right><font face="verdana"
size="-2">100%</font></td>
</tr>
</table>

......

<!-- INPUT LAYOUT START -->
<table cellspacing=2 cellpadding=0 style="behavior:
url(/behaviors/rankedOrder2.htc)" p_questionType="multi" >
<tr>
<td nowrap><input tabindex="1" type="text" name="QTicked2_1"
size="3" value="" id="QTicked2_1">&nbsp;&nbsp;&nbsp;&nbsp;<font
face="verdana" size="-1" color="#990033"><LABEL
FOR="QTicked2_1">Island</LABEL></font></td>
</tr>
<tr>
<td nowrap><input tabindex="2" type="text" name="QTicked2_2"
size="3" value="" id="QTicked2_2">&nbsp;&nbsp;&nbsp;&nbsp;<font
face="verdana" size="-1" color="#990033"><LABEL
FOR="QTicked2_2">Seal</LABEL></font></td>
</tr>
<tr>
<td nowrap><input tabindex="3" type="text" name="QTicked2_3"
size="3" value="" id="QTicked2_3">&nbsp;&nbsp;&nbsp;&nbsp;<font
face="verdana" size="-1" color="#990033"><LABEL
FOR="QTicked2_3">Egypt</LABEL></font></td>
</tr>
<tr>
......

<td nowrap><input tabindex="4" type="text" name="QTicked2_4"
size="3" value="" id="QTicked2_4">&nbsp;&nbsp;&nbsp;&nbsp;<font
face="verdana" size="-1" color="#990033"><LABEL
FOR="QTicked2_4">Bike</LABEL></font></td>
</tr>
<tr>
<td nowrap><input tabindex="5" type="text" name="QTicked2_5"
size="3" value="" id="QTicked2_5">&nbsp;&nbsp;&nbsp;&nbsp;<font
face="verdana" size="-1" color="#990033"><LABEL
FOR="QTicked2_5">Greece</LABEL></font></td>
</tr>
<tr>
<td nowrap><input tabindex="6" type="text" name="QTicked2_6"
size="3" value="" id="QTicked2_6">&nbsp;&nbsp;&nbsp;&nbsp;<font
face="verdana" size="-1" color="#990033"><LABEL
FOR="QTicked2_6">Egypt</LABEL></font></td>
</tr>
</table>
<!-- INPUT LAYOUT END -->
 
B

Bobbo

The first one alert returns the first table, but the second alert gives
an error....

Try making a separate page with just two tables and some cut-down
javascript, then you'll be able to see more clearly what's going on.

e.g. The following code shows you the Id (if any) and how many rows are
in each of the tables on your page. Alter the alert statement and see
what happens.

var tabs = document.getElementsByTagName("table");
var i = 0;
for(i = 0; i < tabs.length; i++)
{
alert(tabs.id);
alert(tabs.getElementsByTagName("tr").length);
}
 
B

bradley_d_watkins

Thanks, I will give this a try.

I think the behaviour of this statement within the table-
style="behavior: url(/behaviors/rankedOrder2.htc)" - is changing the
tables scope somehow.

I will push on though...

Cheers
 
H

Harlan Messinger

Hi

The following worked, however it only returns the first table object on
the webpage. The problem occurs when I need to access subsequent
tables....

It should work. But we can't guess why you had a problem if you don't
show your code.
 

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,208
Messages
2,571,083
Members
47,683
Latest member
AustinFairchild

Latest Threads

Top