469,609 Members | 2,243 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

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
Expand|Select|Wrap|Line Numbers
  1. <TABLE>
  2.  <TR>
  3.   <TD>xyz</TD>
  4.   <TD>xxx</TD>
  5.  </TR>
  6.  <TR>
  7.   <TD>abc</TD>
  8.   <TD>aaa</TD>
  9.  </TR>
  10. </TABLE>
  11.  
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.
Expand|Select|Wrap|Line Numbers
  1.  
  2. <TD onClick="GetVal(this);">xyz</TD>
  3.  
is this possible?

how can i manipulate the values sent to the function?
Oct 26 '10 #1
1 1593
Dormilich
8,652 Expert Mod 8TB
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.
Expand|Select|Wrap|Line Numbers
  1. // W3C
  2. <tr onclick="alert(this.textContent)">
Oct 26 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Solution2021 | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.