Forum Moderators: open

Message Too Old, No Replies

Can somePlease help me! URGENT! please please with sugar on top

cast innerHtml to input

         

javaScriptFool

12:26 pm on Apr 19, 2005 (gmt 0)



Hello all,
i am out on workexperience and i have only started to learn javascript. The people i am working for have asked me to do a project.
i am having a little bit of trouble.
I have a table that i want to extract data from - the data is numeric. the problem is that this table is dynamic-it keeps on changing in size depending on the user. i want a way to acess elements in the table this is the code i am using but is no good. if anyone coudl help i would really be greatfull.

function getCellByRowCol(rowNum, colNum)
{
var tableElem = document.getElementById('tblTest');
var rowElem = tableElem.rows[rowNum+1];
var tdValue = rowElem.cells[colNum+1].innerHTML
return tdValue;
}

the elements of the table are <input type="text"> and i need some way to get the numbers out. if you could help please.

Bernard Marx

1:52 pm on Apr 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



function getCell(tableId,iRow,iCol)
{
var table = document.getElementById(tableId);
var input = table.rows(iRow).cells(iCol).getElementsByTagName('input')[0];
return input && Number(input.value); /*if no input, will return null, without error */
}

Note:

- <cellRef>.childNodes[0].value is unsafe,
due to the possible presence of empty text nodes.

Do I get a cup of tea with that?