By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,421 Members | 1,238 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,421 IT Pros & Developers. It's quick & easy.

How to get the contents of an entire table-row on its onClick() event?

100+
P: 157
Hi,

I have a dynamic table(nx3);id:Tab1.
At the time of creating it I’m assigning a unique row-id(R1,R2…) to every row and a unique column-id to the cells of that row(viz cells of row #1 are:-R1C1,R1C2,R1C3 ; row #2 :-R2C1,R2C2,R2C3 ..)

Is there a straightforward way through JS to get the cell-contents of a row on its click event ie. if I click row #3 then something that would tell me, "you clicked on row #3 and its contents are:- #R3C1=1 #R3C2=‘abctech’ #R3C3=‘31/01/07’ "??

Presently I can retrieve the row-id saying <tr onClick= “func(this.id)”> and

func(id)
{
alert(“Row Id: “ + id );
}

This is fairly simple but still cant figure out how to get the column-ids of this particular row and their contents?
Any idea anyone?
Jan 31 '07 #1
Share this Question
Share on Google+
3 Replies

100+
P: 157
I figured it out,it can be done by using :-
[HTML]document.getElementById("td1").innerHTML ;[/HTML]
where td1 is the id of any cell of a table and the 'innerHTML' property sets or returns the HTML between the start and end tags of a table cell .
Sorry for the trouble! Cheers!
Jan 31 '07 #2

acoder
Expert Mod 15k+
P: 16,027
Well that's the easy non-standard way. The standard way involves the HTML DOM. See here, but in this case, it might be a bit overkill.
Jan 31 '07 #3

100+
P: 157
Well that's the easy non-standard way. The standard way involves the HTML DOM. See here, but in this case, it might be a bit overkill.
Thank you acoder, this seems to be the proper way of retrieving the cells of a row and their content, many thanks for recommending !!!
Feb 1 '07 #4

Post your reply

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