471,089 Members | 1,279 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,089 software developers and data experts.

script doesn't work in firefox:Error: obj.cells has no properties.

Hi,

I have a script here which will loop thru a table and check for it's
background color.

But it doesn't work on Firefox. The Error Inspector said "ERROR. obj.cells
has no properties

How should I work around it to ensure it works for IE and FF?

Thanks

function getselected()
{
var obj;
obj = document.getElementById('t1');
var cellsarr = new Array();
var chosenarr = new Array();
for(var i = 0; i<obj.cells.length;i++)
{
cellsarr[cellsarr.length]=obj.cells[i];
if(obj.cells[i].getAttribute('bgColor')=='#000000')
{
alert(obj.cells[i].id);
}
}

alert(cellsarr.length);

}

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Feb 4 '07 #1
3 1888
Eric Layman wrote:
Hi,

I have a script here which will loop thru a table and check for it's
background color.

But it doesn't work on Firefox. The Error Inspector said "ERROR. obj.cells
has no properties
That would indicate that obj.cells has no properties, i.e. it isn't an
object.
>
How should I work around it to ensure it works for IE and FF?

Thanks

function getselected()
{
var obj;
obj = document.getElementById('t1');
What is obj now?

var cellsarr = new Array();
var chosenarr = new Array();
for(var i = 0; i<obj.cells.length;i++)
The only W3C DOM object that has a cells property is one that implements
the HTMLTableRowElement interface. If obj isn't a table row element,
it will only have a cells property if you gave it one.

I'll guess that obj is a reference to a table. If you want to loop over
all the cells in a table, you'll have to loop over the rows first,
something like:

var rows = obj.rows;
var cell, cells;
for (var i=0, len=rows.length; i<len; i++){
cells = row[i].cells;
for (var j=0, len2=cells.length; j<len; j++){
cell = cells[i];
/* do stuff with each cell */
}
}

{
cellsarr[cellsarr.length]=obj.cells[i];
Consider:

cellsarr[i]=obj.cells[i];
--
Rob
Feb 4 '07 #2

"RobG" <rg***@iinet.net.auwrote in message
news:45***********************@per-qv1-newsreader-01.iinet.net.au...
Eric Layman wrote:
>Hi,

I have a script here which will loop thru a table and check for it's
background color.

But it doesn't work on Firefox. The Error Inspector said "ERROR.
obj.cells has no properties

That would indicate that obj.cells has no properties, i.e. it isn't an
object.
>>
How should I work around it to ensure it works for IE and FF?

Thanks

function getselected()
{
var obj;
obj = document.getElementById('t1');

What is obj now?

> var cellsarr = new Array();
var chosenarr = new Array();
for(var i = 0; i<obj.cells.length;i++)

The only W3C DOM object that has a cells property is one that implements
the HTMLTableRowElement interface. If obj isn't a table row element, it
will only have a cells property if you gave it one.

I'll guess that obj is a reference to a table. If you want to loop over
all the cells in a table, you'll have to loop over the rows first,
something like:

var rows = obj.rows;
var cell, cells;
for (var i=0, len=rows.length; i<len; i++){
cells = row[i].cells;
for (var j=0, len2=cells.length; j<len; j++){
cell = cells[i];
/* do stuff with each cell */
}
}

> {
cellsarr[cellsarr.length]=obj.cells[i];

Consider:

cellsarr[i]=obj.cells[i];
--
Rob
Thanks Rob! Finally got it to work wif FF.

This shows that IE do not follow W3C recommendations?

But your inner for loop should read as

for (var j=0, len2=cells.length; j<len2; j++)

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Feb 4 '07 #3
On Feb 5, 10:35 am, "Eric Layman" <erricson@layswrote:
[...]
Thanks Rob! Finally got it to work wif FF.

This shows that IE do not follow W3C recommendations?
Something of an understatement ;-) but there is nothting that says a
table can't have a cells collection too.
>
But your inner for loop should read as

for (var j=0, len2=cells.length; j<len2; j++)
Yes.
--
Rob

Feb 4 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jatinder Singh | last post: by
5 posts views Thread by Tam Inglis | last post: by
1 post views Thread by key3210 | last post: by
8 posts views Thread by jayavidya | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.