Anon wrote:
I have a table with a cell. The cell's ID is created using a unique
name that
is held in m_UniqueCellName and the cell is created like so...
document.write( "<TD ID="' + m_UniqueCellName + '"></TD>" );
How can I programmatically modify the contents of the cell whose name
is held within m_UniqueCellName? The variable will get passed around
to other functions, but try as I might,
myid = document.getElementById( m_UniqueCellName );
document.all.myid.innerHTML = "Something!";
simply doesn't work. What is it that I'm missing? Any help would be
greatly appreciated.
When you create m_UniqueCellName, it is just a string that has
no special properties.
When you use document.write, you have created HTML that is
parsed by the browser and rendered in a browser window. You
never created a reference to the cell you create, hence you
don't have one to 'remember'. m_UniqueCellName will only refer
to the original variable which contains a string.
If you want to create the cell in a manner that allows you to
reference it later, use DOM methods to build your table. Or,
if you create m_UniqueCellName as global variable (not recommended),
you can later get a reference to the cell using:
if (document.getElementById) {
var myid = document.getElementById(m_UniqueCellName);
} else if (document.all) {
var mtid = document.all(m_UniqueCellName);
}
myid.innerHTML = 'something!';
As noted elsewhere, innerHTML is a Microosft invention that is
not part of any W3C standard, it should be used judiciously.
If you want to manipulate the contents of a table cell you
should use DOM methods, however if all that is required is the
simple replacement of some text in the cell, it is fine in most
cases.
--
Rob