[resolved][Javascript] Find datagrid <input> text element values for only one column
I have a datagrid on an asp.net page and I need to find the values in embedded <input> text element controls only for a certain column in order to sum these values.
This javascript only gets me down to the <td>'s I need and I can't go any further to get to the <input>'s and get the values. Not all cells in this column have embedded <input> elements.
PHP Code:
function GetValues()
{
// get datagrid by rendered table name
var grid = document.getElementById('datagrid1');
var len = grid.rows.length;
// touch each row, retrieve cell 2 innerHTML
for(i = 0; i < len; i++)
{
// show raw text for cells, <input type="text"... > for text box
alert(grid.rows[i].cells[2].innerHTML);
}
}
How can I get the values of the <input> text elements?
Re: Find datagrid <input> text element values for only one column [Javascript]
Untested and been a while again since I touched JavaScript, but here's a try:
PHP Code:
// in the loop
var inputelements = grid.rows[i].cells[2].getElementsByTagName('input');
var maxj = inputelements.length;
for(j = 0; j < maxj; j++)
{
if(inputelements[j].getAttribute('type') == 'text') {
alert(inputelements[j].getAttribute('value'));
}
}
Re: Find datagrid <input> text element values for only one column [Javascript]
Re: [resolved][Javascript] Find datagrid <input> text element values for only one column
Fantastic. I've been looking for a solution to this for a couple of weeks now. My javascript has become a bit rusty but this works perfectly. So a huge thank you.:)