...

View Full Version : Selecting Table Rows



mark87
01-29-2006, 12:02 PM
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!


<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>

vwphillips
01-29-2006, 12:39 PM
<!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>

mark87
01-29-2006, 12:54 PM
Cheers. :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum