By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,340 Members | 1,625 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,340 IT Pros & Developers. It's quick & easy.

get a table cell value

P: n/a
let's say this is a html table, how can i get the string value contained in
the X cell ?

---------------------
| | | |
---------------------
| | | |
---------------------
| X | | |
---------------------
| | | |
---------------------

thanks
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"yukatan" <a@a.com> writes:
let's say this is a html table, how can i get the string value contained in
the X cell ?
Don't draw using a proportional font. There is little chance that the
receiver uses the same proportional font. If you draw using a fixed
width font, then at least all other fixed width fonts will give a
correct drawing. My newsreader uses a fixed with font, as does a lot
of others.

---------------------
| | | |
---------------------
| | | |
---------------------
| X | | |
---------------------
| | | |
---------------------


To get the cell, assuming that the id of the table is "tableId":

var table = document.getElementById("tableId");
var row = table.rows[2];
var cell = row.cells[0];

The hard part is getting the content of the cell. If it is plain,
unstyled text, then you can probably use:

var content = cell.firstChild.nodeValue;

Otherwise you must either use proprietary methods like cell.innerText
that doesn't work in all modern browsers, or you must gather the text
recursively. Since you just say "string value", I assume it is plain,
unstyled text.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

P: n/a
In article <ll**********@hotpop.com>, Lasse Reichstein Nielsen <lr*@hotpop.com>
writes:
Otherwise you must either use proprietary methods like cell.innerText
that doesn't work in all modern browsers, or you must gather the text
recursively. Since you just say "string value", I assume it is plain,
unstyled text.


Whether its styled text or not, why not innerHTML if you get out of the W3C and
into proprietary? At least allows it to work somewhere besides IE :(
--
Randy
Jul 20 '05 #3

P: n/a
hi************@aol.com (HikksNotAtHome) writes:
Whether its styled text or not, why not innerHTML if you get out of
the W3C and into proprietary? At least allows it to work somewhere
besides IE :(


Yes, but that doesn't get the text of styled content, but the HTML code.
You will have to remove the tags to get just the text.

It all depends on what the original poster wants, which wasn't clear.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.