onclick get another cells innerText

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • oembuilders@gmail.com

    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.srcEleme nt.cellIndex == "1")
    {
    event.returnVal ue = false;
    alert(event.src Element.innerTe xt);
    }


    Fails to get innertext for cell(10)
    *************** *************** ******
    if (event.srcEleme nt.cellIndex == "1")
    {
    event.returnVal ue = false;
    alert(event.src Element.cells(1 0).innerText);
    }

  • Dietmar Meier

    #2
    Re: onclick get another cells innerText

    oembuilders@gma il.com wrote:
    [color=blue]
    > Having a bit of trouble figuring out how to get the innerText of
    > a cell other that the one selected.[/color]

    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.srcEleme nt)) {
    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(ev ent)">
    <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>


    Comment

    • oembuilders@gmail.com

      #3
      Re: onclick get another cells innerText

      Thanks,

      Worked like carm.

      Comment

      Working...