mouseover a tables cell.

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

    #1

    mouseover a tables cell.

    I want to retreive the row number of a cell in the table when the
    mouse is over that cell.
    Can any one help?
  • mscir

    #2
    Re: mouseover a tables cell.

    hari wrote:[color=blue]
    > I want to retreive the row number of a cell in the table when the
    > mouse is over that cell. Can any one help?[/color]

    will this do it for you?

    <script type="text/javascript">
    function showrow(tbl_row ){
    alert(tbl_row);
    }
    </script>

    <table>
    <tr onmouseover="sh owrow('row1')">
    <td>a</td>
    <td>b</td>
    </tr>
    <tr onmouseover="sh owrow('row2')">
    <td>e</td>
    <td>f</td>
    </tr>
    <tr onmouseover="sh owrow('row3')">
    <td>i</td>
    <td>j</td>
    </tr>
    <tr onmouseover="sh owrow('row4')">
    <td>m</td>
    <td>n</td>
    </tr>
    </table>

    Comment

    • Michael Winter

      #3
      Re: mouseover a tables cell.

      On 8 Oct 2004 13:05:46 -0700, hari <sivaprasad.ps@ tcs.com> wrote:
      [color=blue]
      > I want to retreive the row number of a cell in the table when the
      > mouse is over that cell.
      > Can any one help?[/color]

      With modern, DOM-supporting browsers, you can obtain the parent of the
      table (the row), and get the row index of that via a property.

      <tr>
      <td onmouseover="ge tRowIndex(this) ;">
      ...


      function getRowIndex(cel l) {
      var row = cell.parentNode ;
      if(row && 'undefined' != typeof row.rowIndex) {
      return row.rowIndex; // or row.sectionRowI ndex
      }
      }

      The difference between rowIndex and sectionRowIndex is that the former
      runs throughout the entire table. The latter restarts at the beginning of
      each table section (TBODY, THEAD and TFOOT). Indicies are zero-order.

      Hope that helps,
      Mike

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

      Comment

      Working...