How can I Get the cell values when it is clicked

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Hiroyuki

    #1

    How can I Get the cell values when it is clicked

    Hello..please help with my problem since Im new in using
    HTML and javascript.

    I have this table that has rows and columns.
    Hello..please help me with my problem since Im new in using
    HTML and javascript.

    I have this table that has rows and columns.
    When i click the value of the cell, it will return
    the values of the cells of the same row.

    Example
    Code:
    <TABLE>
     <TR>
      <TD>xyz</TD>
      <TD>xxx</TD>
     </TR>
     <TR>
      <TD>abc</TD>
      <TD>aaa</TD>
     </TR>
    </TABLE>
    So if I click cell with xyz value, it should return xyz and xxx values.

    Im thinking of using onClick in TD tag then get the values as arguments
    for the function.
    Code:
     
    <TD onClick="GetVal(this);">xyz</TD>
    is this possible?

    how can i manipulate the values sent to the function?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    when you execute the function, you don’t get both values as parameters, but you can access them inside the function.

    it’s probably easier to attach the handler to the table row.
    Code:
    // W3C
    <tr onclick="alert(this.textContent)">

    Comment

    Working...