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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric Layman

    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.getEle mentById('t1');
    var cellsarr = new Array();
    var chosenarr = new Array();
    for(var i = 0; i<obj.cells.len gth;i++)
    {
    cellsarr[cellsarr.length]=obj.cells[i];
    if(obj.cells[i].getAttribute(' bgColor')=='#00 0000')
    {
    alert(obj.cells[i].id);
    }
    }

    alert(cellsarr. length);

    }



    Posted Via Usenet.com Premium Usenet Newsgroup Services
    ----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
    ----------------------------------------------------------
    Best Usenet Service Providers 2025 ranked by Newsgroup Access Newsservers, Usenet Search, Features & Free Trial. Add VPN for privacy.

  • RobG

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

    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.getEle mentById('t1');
    What is obj now?

    var cellsarr = new Array();
    var chosenarr = new Array();
    for(var i = 0; i<obj.cells.len gth;i++)
    The only W3C DOM object that has a cells property is one that implements
    the HTMLTableRowEle ment 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.leng th; j<len; j++){
    cell = cells[i];
    /* do stuff with each cell */
    }
    }

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

    cellsarr[i]=obj.cells[i];


    --
    Rob

    Comment

    • Eric Layman

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


      "RobG" <rgqld@iinet.ne t.auwrote in message
      news:45c587df$0 $25307$5a62ac22 @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.getEle mentById('t1');
      >
      What is obj now?
      >
      >
      > var cellsarr = new Array();
      > var chosenarr = new Array();
      > for(var i = 0; i<obj.cells.len gth;i++)
      >
      The only W3C DOM object that has a cells property is one that implements
      the HTMLTableRowEle ment 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.leng th; 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.leng th; j<len2; j++)



      Posted Via Usenet.com Premium Usenet Newsgroup Services
      ----------------------------------------------------------
      ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
      ----------------------------------------------------------
      Best Usenet Service Providers 2025 ranked by Newsgroup Access Newsservers, Usenet Search, Features & Free Trial. Add VPN for privacy.

      Comment

      • RobG

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

        On Feb 5, 10:35 am, "Eric Layman" <erricson@laysw rote:
        [...]
        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.leng th; j<len2; j++)
        Yes.


        --
        Rob

        Comment

        Working...