PDA

View Full Version : How to dynamically change content of a TD



azstyx
Mar 28th, 2005, 08:35 PM
Hello Team,
I need to dynamically change the content of a particular TD.
Table def:
<table>
<tr>
<td ID="T1D1">
Old Data
</td></tr>
</table>
I have tried this mehtod and it does not work:
document.getElementById("T1D1").setAttribute("nodeValue", "");

What do I need to do to reference the content of the TD and change it?
Thanks!!
Styx



My HTML code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>JS Table Play</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript1.2" type="text/JavaScript">
<!--
function listt1d1attr() {
var auxwin = window.open("","auxwindow");
// list attributes of a TD element
var mytd = document.getElementById("T1D1");
var td_nodemap = mytd.attributes;
auxwin.document.writeln("List of Attributes for T1D1<br>");
for (x=0; x<td_nodemap.length; x++) {
var attr = td_nodemap.item(x);
auxwin.document.writeln("Attr Name=>"+attr.name+" Attr Value=>"+attr.value+"<br>");
}

}
function clearT1D1() {
//var auxwin = window.open("","auxwindow");
// clear contents of TD element
document.getElementById("T1D1").setAttribute("value", "");



}
// -->
</script>
</head>
<body>
<table width="300" border="1" cellspacing="0" cellpadding="0" ID=T1>
<tr>
<th>Table#1 Header</th>
</tr>
<td id="T1D1">example table line</td></tr>
</TABLE>
<br>

<h1>JS Table Test</h1>
<FORM action="" method="GET" name="myForm" id="myForm" >
<input type="BUTTON" name="btntda" id="btntda" value="List T1D1 Attrs"
onClick="listt1d1attr();"><br>
<input type="BUTTON" name="btntdc" id="btntdc" value="Clear value T1D1"
onClick="clearT1D1();"><br>
</FORM>
</body>
</html>

Harry Armadillo
Mar 29th, 2005, 02:14 AM
document.getElementById("T1D1").innerHTML="whatever"

and please use [code] tags when posting your code; it preserves the formatting and is much easier to read.

azstyx
Mar 29th, 2005, 05:31 PM
GREAT!!!!! THX Harry!
:)