SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    td onclick problems

    i need to get the values of the cell in the same row when i click the cell. the table is generated using document.write.

    sample code

    <script type="text/javascript">
    function cmsSearch(){
    var winnew = window.open("result.html", "result", status)
    winnew.document.write("<table>");
    winnew.document.write("<tr>");
    winnew.document.write("<td onclick='getVal(this)'>xxx</td>");
    winnew.document.write("<td>yyy</td>");
    winnew.document.write("</tr>");
    winnew.document.write("</table>");
    }

    function getVal(e){
    var row= e.parentNode;
    var s= "";
    for(var i=0; i<row.cells.length;i++){
    s+= row.cells[i].innerText;
    }
    alert(s);
    }

    when i click cell that has a value of xxx, xxx and yyy will be used as arguments to function getVal(). problem is runtime error occura and it needs an object. what seems to be the problem?

  2. #2
    SitePoint Zealot
    Join Date
    May 2009
    Location
    Netherlands
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    function cmsSearch(){
    var winnew = window.open("result.html", "result", status)
    winnew.document.write("<table>");
    winnew.document.write("<tr>");
    winnew.document.write("<td onclick='opener.getVal(this)'>xxx</td>"); // referencing error
    winnew.document.write("<td>yyy</td>");
    winnew.document.write("</tr>");
    winnew.document.write("</table>");
    winnew.document.close(); //always close an opened document
    }
    
    function getVal(e){
    var row= e.parentNode;
    var s= "";
    for(var i=0; i<row.cells.length;i++){
    s+= row.cells[i].firstChild.data; // innerText will only work in IE
    }
    alert(s);
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •