Get data from textbox inside a table

S

Simon

Hello,

how can i get data from this table:
<table>
<tr><td>someText</td></tr>
<tr><td>
<input name="DataGrid1:_ctl2:textBox" type="text" value="someText"
id="DataGrid1__ctl2_textBox" style="width:140px;" />
</td></tr>
</table>


for the first column I can use:
var column1 = table.rows[rowIndex].cells[0].childNodes[0].data;
and I get 'someText'

how can I get text from column2 ('someText2')?

Thanks
 
T

Thomas 'PointedEars' Lahn

Simon said:
how can i get data from this table:
<table>
<tr><td>someText</td></tr>
<tr><td>
<input name="DataGrid1:_ctl2:textBox" type="text" value="someText"
id="DataGrid1__ctl2_textBox" style="width:140px;" />
</td></tr>
</table>


for the first column I can use:
var column1 = table.rows[rowIndex].cells[0].childNodes[0].data;

I would use the generic

var column1 = table.rows[rowIndex].cells[0].childNodes[0].nodeValue;

with the more reliable

var column1 = [];

for (var c = table.rows[rowIndex].cells[0].childNodes, i = 0;
i < c.length; i++)
{
column1.push(c[0].nodeValue);
}

column1 = column1.join("");

or (from DOM Level 3 Core)

var column1 = table.rows[rowIndex].cells[0].textContent;
and I get 'someText'

how can I get text from column2 ('someText2')?

Column 2 does not contain non-whitespace text nodes, therefore .textContent
will not yield anything but whitespace.

Suppose you wish to retrieve the value of the `input' element, you would
retrieve the object reference with

var o = document.forms[...].elements["DataGrid1__ctl2_textBox"];

(preferable) or

var o = document.getElementById("DataGrid1__ctl2_textBox");

and then (after a runtime feature test) access

o.value


BTW, the first `td' element should probably be a `th' element.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Thomas said:
var column1 = [];

for (var c = table.rows[rowIndex].cells[0].childNodes, i = 0;
i < c.length; i++)
{
column1.push(c[0].nodeValue);

Should read

column1.push(c.nodeValue);

of course.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top