PDA

View Full Version : get the object value after using getElementById


paula dougherty
08-25-2006, 11:23 AM
Hi

See code below, I've built a table on the fly within a js function.
In another function I'm trying to get the value of a cell in a particular row on that table. I've retrieved the cell object but cannot get it's value ...
any ideas please ??

got the cell obbject by ..

var claimDate = parent.expenseDisplay.document.getElementById("row"+lineNo+"Date");

now I thought that the following would give the the data
var cdate = getObject(claimDate).value;

Kor
08-25-2006, 03:25 PM
what do you mean by cells's value? A cell has no value. You mean maybe the content of the cell?

paula dougherty
08-25-2006, 03:28 PM
Yep , I meant the contents of the cell.

Kor
08-25-2006, 03:39 PM
it depends on how your content looks like. And on the position of that cell in the row.If a simple text in the first cell:

<tr id="row2Date">
<td>some text</td>
</tr>

var mytext=document.getElementById('row2Date').getElementsByTagName('td')[0].firstChild.data

Basscyst
08-26-2006, 02:08 AM
I have more luck with:


. . .getElementsByTagName('td')[0].firstChild.nodeValue


What's the difference? I seem to remember .data giving me an error in some browser(s).

Kravvitz
08-26-2006, 04:10 AM
The data property is limited to text and comment nodes; nodeValue is for all nodes. On text and comment nodes the properties have the same value.

So if you try accessing the data property on an element node, you will get an error unless you have assigned a custom property named "data" to it.