Click to See Complete Forum and Search --> : Table Row Events


gnanesh
07-18-2003, 07:20 AM
hi

I have a table with all TR'S & TD'S , When i display the table the user should be able to click on any Row's to see that particular information, It display's a FORM when the user selects Row and we are providing options like create,update,search or delete ,

I need to know how do i call any javascript functions from any TR's so that i get all TD'S data corresponding to that TR

<table>
<tr onclick="abc(this);">
<td class="td1">Sam</td>
<td class ="td1">California</td>
</tr>
</table>

If any one knows how to get all the TD values of a particular TR please let me know, I appreciate if you could post me some code on this

Regards
GG

gil davis
07-18-2003, 07:39 AM
Assuming you can actually click on a TR (I don't believe that it should work), you would navigate the DOM tree using the firstChild of the TR (this.firstChild) to get the first TD, and then use nextSibling until there aren't any more.

You can also use:
this.getElementsByTagName("td")
to get an array of all the TD elements in the row (represented by "this").

gnanesh
07-18-2003, 08:18 AM
thanks

how do i get the values of all these TD'S ?

if i do

this.getElementByTagName('td').value

will i get the values back ?

Let me know about this

Regards
Gnanesh

Mr J
07-18-2003, 09:22 AM
Have a try at the following



<table border="1">
<tr id="row1" onClick="alert(row1_td1.innerHTML+'\n'+row1_td2.innerHTML)">
<td id="row1_td1">TD CELL ONE</td><td id="row1_td2">TD CELL TWO</td>
</tr>
<tr id="row2" onClick="alert(row2_td1.innerHTML+'\n\n'+row2_td2.innerHTML)">
<td id="row2_td1"> Data Data Data</td><td id="row2_td2">More Data in Row 2 td 2</td>
</tr>
</table>