onclick get another cells innerText

O

oembuilders

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);
}
 
D

Dietmar Meier

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top