473,395 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Modify table cell...

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.
Jul 23 '05 #1
6 4966
Ivo
"Anon" wrote
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.


You made myid reference to the object itself, not to its name, which is what
document.all expects. Try:

myid.innerHTML="Yes!";
or
document.all[ m_UniqueCellName ].innerHTML = "Something!";

Note the dot following the closing ] and the absence of one preceding the [.
The first option is the prefered one as document.all is not part of any
standard (neither is innerHTML btw).

hth
--
Ivo
http://4umi.com/
Jul 23 '05 #2
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

Jul 23 '05 #3

"Ivo" <no@thank.you> wrote in message
news:42*********************@news.wanadoo.nl...
You made myid reference to the object itself, not to its name, which is
what
document.all expects. Try:

myid.innerHTML="Yes!";
or
document.all[ m_UniqueCellName ].innerHTML = "Something!";


Thanks Ivo, the second method works perfectly, however I'd feel more
comfortable if I could get the first method working too. ;-)
Jul 23 '05 #4
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>" );

document.write( "<TD ID='" + m_UniqueCellName + "'></TD>" );

Mick
Jul 23 '05 #5

"RobG" <rg***@iinet.net.au> wrote in message
news:11********************@l41g2000cwc.googlegrou ps.com...
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.


I used the DOM methods to create a Table, then added a row like so,

var cell = document.createElement( "TD" );
cell.className = m_UniqueCellName ;
cell.appendChild( document.createTextNode( "Some Cell" ) );

However, the following code only works in IE and Opera, but not NN
or Firefox (all browsers are the latest version):

m_UniqueCellName.document.write( "hello" );

But there's also the added effect that (in IE and Opera), while the cell
contents are indeed changed, the entire contents of the page are erased.
Jul 23 '05 #6
Anon wrote on 12 mrt 2005 in comp.lang.javascript:

"RobG" <rg***@iinet.net.au> wrote in message
news:11********************@l41g2000cwc.googlegrou ps.com...
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.
I used the DOM methods to create a Table, then added a row like so,

var cell = document.createElement( "TD" );
cell.className = m_UniqueCellName ;


m_UniqueCellName returns a string? Or is it a function?
cell.appendChild( document.createTextNode( "Some Cell" ) );

However, the following code only works in IE and Opera, but not NN
or Firefox (all browsers are the latest version):
You cannot use a class [className] as a name or an id

You should not use a name as an id, and let the name be used as an
object variable, when wanting to be somewhat cross browser compatible.

You should use an id and use getElementById() to be somewhat cross
browser compatible.
m_UniqueCellName.document.write( "hello" );
m_UniqueCellName.document.write()

The cell [that is referenced incorrectly, see above,] is NOT a child of
the document. Your code is nonsensical. Review in your mind the DOM tree.

But there's also the added effect that (in IE and Opera), while the
cell contents are indeed changed, the entire contents of the page are
erased.


A logical consequence of using document.write() in a finished page.
Then document.write() calls document.open() first.

Is m_UniqueCellName perhaps an alias of window[]?

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Franco Fellico' | last post by:
Hi. Suppose to have read and displayed (using PHP) a group of row of a DB table on a dinamyc table on a HTML/PHP page. The number of row displayed could be from 1 to n. Each row contains...
1
by: Stefan Mueller | last post by:
I'd like to read and modify a cell (e.g. 'Text 1') in the following HTML table with a JavaScript: ============================================== <html> <body> <table id = "MyTable"> <tr id...
7
by: slitvinov | last post by:
I am learning Relax NG. The problem is that I cannot figure out how to make a schema for a table. In my case I would like to make a table with any name of child elements (columns) but columns...
1
by: Wescotte | last post by:
I'm having problems changing a table from a child window. What works (but I really want to add more complex objects to teh cells not just plain text) var myTable =...
4
by: mimasci | last post by:
Hi, I have tried to write a code that allowed me to modify the value of the cells selected in a table, with excel has been easy. How one approaches selected cells? (To modify the value) How...
4
by: [Jongware] | last post by:
I'm a bit stumped about this request on an Adobe forum. Apparently, exporting a table from their flagship InDesign to XML produces the following output for a table (only first 2 rows listed; after...
0
by: camaro71 | last post by:
Hi there, I really hope someone can help with this one. I have a simple recorded macro (code below) which I'm trying to modify. It's for use in MS Word 2003 tables: With the cursor in front of a...
2
by: Albin | last post by:
Hi, I have a html page where in the table spans for two pages the first page's last row doesn end properly and the 2nd page's first row also isnt proper.The code i use is given below,the no of...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.