this.rowIndex question

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

    this.rowIndex question

    Folks,

    Can someone please tell me why this simple piece of code, irritatingly,
    fails to give the expected result?

    Regards
    Rae MacLeman

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title>Sample Code</title>
    </head>
    <body>
    <table id="table1" border="1">
    <tr>
    <td onClick="alert( this.rowIndex); ">Tell me which row</td>
    </tr>
    <tr>
    <td onClick="alert( this.rowIndex); ">Tell me which row</td>
    </tr>
    <tr>
    <td onClick="alert( this.rowIndex); ">Tell me which row</td>
    </tr>
    </table>
    </body>
    </html>


    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.775 / Virus Database: 522 - Release Date: 10/8/04


  • Michael Winter

    #2
    Re: this.rowIndex question

    On Sun, 10 Oct 2004 18:45:23 +0100, webdev <someone@micros ofdt.com> wrote:
    [color=blue]
    > Can someone please tell me why this simple piece of code, irritatingly,
    > fails to give the expected result?[/color]

    [snip]
    [color=blue]
    > <td onClick="alert( this.rowIndex); ">Tell me which row</td>[/color]

    [snip]

    Table cells don't have a rowIndex property, rows do.

    onclick="alert( this.parentNode .rowIndex);"

    retrieves the containing row, and its index within the table.

    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.

    Comment

    • Richard Cornford

      #3
      Re: this.rowIndex question

      webdev wrote:[color=blue]
      > Can someone please tell me why this simple piece of code,
      > irritatingly, fails to give the expected result?[/color]

      Not unless you state what your expectation is. I would be expecting the
      alerts to report "undefined" or fail to operate (having no string
      argument) depending on the browser.

      <snip>[color=blue]
      ><tr>
      > <td onClick="alert( this.rowIndex); ">Tell me which row</td>
      ></tr>[/color]
      <snip>

      Are you expecting the TD elements to have a rowIndex property? If you
      are interested in the rowIndex of the containing TR you might try -
      this.parentNode .rowIndex -.

      Richard.


      Comment

      • webdev

        #4
        Re: this.rowIndex question


        "Richard Cornford" <Richard@litote s.demon.co.uk> wrote in message
        news:ckbuip$qor $1$8302bc10@new s.demon.co.uk.. .[color=blue]
        > webdev wrote:[color=green]
        > > Can someone please tell me why this simple piece of code,
        > > irritatingly, fails to give the expected result?[/color]
        >
        > Not unless you state what your expectation is. I would be expecting the
        > alerts to report "undefined" or fail to operate (having no string
        > argument) depending on the browser.
        >
        > <snip>[color=green]
        > ><tr>
        > > <td onClick="alert( this.rowIndex); ">Tell me which row</td>
        > ></tr>[/color]
        > <snip>
        >
        > Are you expecting the TD elements to have a rowIndex property? If you
        > are interested in the rowIndex of the containing TR you might try -
        > this.parentNode .rowIndex -.
        >
        > Richard.
        >
        >[/color]
        My expectation was that it would return the rowindex ;0)

        I'm wiser now



        ---
        Outgoing mail is certified Virus Free.
        Checked by AVG anti-virus system (http://www.grisoft.com).
        Version: 6.0.775 / Virus Database: 522 - Release Date: 10/8/04


        Comment

        • webdev

          #5
          Re: this.rowIndex question


          "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message
          news:opsfn1pun6 x13kvk@atlantis ...[color=blue]
          > On Sun, 10 Oct 2004 18:45:23 +0100, webdev <someone@micros ofdt.com> wrote:
          >[color=green]
          > > Can someone please tell me why this simple piece of code, irritatingly,
          > > fails to give the expected result?[/color]
          >
          > [snip]
          >[color=green]
          > > <td onClick="alert( this.rowIndex); ">Tell me which row</td>[/color]
          >
          > [snip]
          >
          > Table cells don't have a rowIndex property, rows do.
          >
          > onclick="alert( this.parentNode .rowIndex);"
          >
          > retrieves the containing row, and its index within the table.
          >
          > Mike
          >
          > --
          > Michael Winter
          > Replace ".invalid" with ".uk" to reply by e-mail.[/color]

          Thanks Mike - I'd already tried "parentNode.row Index" somewhere along the
          line.

          Rae


          ---
          Outgoing mail is certified Virus Free.
          Checked by AVG anti-virus system (http://www.grisoft.com).
          Version: 6.0.775 / Virus Database: 522 - Release Date: 10/8/04


          Comment

          Working...