By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,672 Members | 1,306 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,672 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
3 Replies

P: n/a
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

P: n/a

"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

P: n/a
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.