473,320 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

onclick get another cells innerText


Having a bit of trouble figuring out how to get the innerText of
a cell other that the one selected. Any help would be apprecated
as I am very new to javascript. I got the working example from
msdn site.
Get inner text for cell(1) works
**********************************
if (event.srcElement.cellIndex == "1")
{
event.returnValue = false;
alert(event.srcElement.innerText);
}
Fails to get innertext for cell(10)
************************************
if (event.srcElement.cellIndex == "1")
{
event.returnValue = false;
alert(event.srcElement.cells(10).innerText);
}

Jul 23 '05 #1
2 4039
oe*********@gmail.com wrote:
Having a bit of trouble figuring out how to get the innerText of
a cell other that the one selected.


Here's a cross-browser example. If you want innerText (what's MSIE
propietary), use `sText = oTD.innerText´ instead.

function foo(oEvent) {
var oTR, oParent, oTD, oTN;
if ((oTR = oEvent.target || oEvent.srcElement)) {
while (oTR.tagName != "TR" && (oParent = oTR.parentNode)) {
oTR = oParent;
}
if (oTR.cells && (oTD = oTR.cells[2])) {
sText = (oTN = oTD.firstChild) && oTN.nodeType == 3 && oTN.nodeValue;
alert(sText || "not found");
}
}
}
[...]
<table>
<tbody onclick="foo(event)">
<tr>
<td>A1</td><td>A2</td><td>A3</td>
</tr>
<tr>
<td>B1</td><td>B2</td><td>B3</td>
</tr>
<tr>
<td>C1</td><td>C2</td><td>C3</td>
</tr>
</tbody>
</table>
Jul 23 '05 #2
Thanks,

Worked like carm.

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Larry Woods | last post by:
I have created a table that I want to fill with calculated values. I have given ID's to each cell. This must NOT be the way since I can't address these ID's. How do I store values in table cells...
8
by: cool2005 | last post by:
I tried to dynamically add/clone a <tr> from an existing <tr> to a <table> but the problem is that I need to have a "onclick" event handler in the <tr>. I have tried following A. approach...
2
by: Corno | last post by:
Hi all, I have a page with a table of which the rows have to be added dynamically. What I also want is 'code behind' the onclick event of a row (the page should be posted back to the server,...
0
by: Ramesh Chawla | last post by:
Hi, I am making a table in ASP.NET at the runtime and loading the data in the left and the most colums and in between there are 9 columns on which data from either of the columns can be dropped....
7
by: rsaffy | last post by:
I am having trouble with my dynamically created button's event handling. I read that the buttons need to be recreated on every trip to the server, but how exactly do you do that when the datagrid...
11
by: GaryB | last post by:
Hi Guys, I've been battling with this one for hours - I hope that you can help me! My code modifies the <aon a page, from a standard document link into a link with a tailored onclick event. ...
1
by: samn | last post by:
I wrote the following script in order to traverse an HTML table and merge the cells that have the same value across multiple rows. For some reason, however, it works for the first, third, and...
18
by: joaotsetsemoita | last post by:
Hello everyone, I'm having troubles assigning an onclick event to a cell. Im trying something like cursorPoint.cells.style.cursor = "hand"; cursorPoint.cells.width = "20";...
4
by: prosad | last post by:
hello, Just solved a problem using Javascript onclick, can click on any cell in a dynamic table and it will pass the innerText object value to my form text field. parts of code given below: ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.