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

Mar 28th, 2005, 08:35 PM
Hello Team,
I need to dynamically change the content of a particular TD.
Table def:
<td ID="T1D1">
Old Data
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?

My HTML code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<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", "");

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

<h1>JS Table Test</h1>
<FORM action="" method="GET" name="myForm" id="myForm" >
<input type="BUTTON" name="btntda" id="btntda" value="List T1D1 Attrs"
<input type="BUTTON" name="btntdc" id="btntdc" value="Clear value T1D1"

Harry Armadillo
Mar 29th, 2005, 02:14 AM

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

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