Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Selecting Table Rows

    Just playing about really, am trying to add the selected table row values to text area. Tried using childNodes but I guess it doesn't work for table rows (just comes out as '[object] - undefined'). Any better methods? - I don't really want an overly complicated solution, afterall it's just testing to get me back into JavaScript again!

    Code:
    <tr class="a" onclick="this.style.backgroundColor='#3D80DF'; this.style.color='#FFF'; document.getElementById('selected_songs').value = document.getElementById('selected_songs').value + this.childNodes[2] + ' - ' + this.childNodes[3] + '\n'">
    <td>1</td>
    <td>Slit Wrist Theory</td>
    <td>36 Crazyfists</td>
    </tr>

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,535
    Thanks
    3
    Thanked 513 Times in 500 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    <!--
    
    function Cng(obj){
    obj.style.backgroundColor='#3D80DF';
    obj.style.color='#FFF';
     objtds=obj.getElementsByTagName('TD');
     var t=document.getElementById('selected_songs')
     t.value = t.value + objtds[1].innerHTML + ' - ' + objtds[2].innerHTML + '\n'
    }
    //-->
    </script>
    </head>
    <body>
    <table>
    <tr class="a" onclick="Cng(this);">
    <td>1</td>
    <td>Slit Wrist Theory</td>
    <td>36 Crazyfists</td>
    </tr>
    </table>
    <textarea id="selected_songs" rows="2" cols="100"></textarea>
    </body>
    
    </html>

  • #3
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Cheers.


  •  

    Posting Permissions

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