PDA

View Full Version : accessing auto generated table elements


aido179
12-01-2009, 12:23 PM
hi all, i think im in the right place, if not, feel free to move.
I am an IT student and currently working on an assignment involving creating a form in javascript to deal with inputs about an energy audit.

Im using a function called addRoom() to add a new row, cells and innerHTML to a table.

Code:
function addRoom()
{
if (roomApps > 0 || currentRow == 0)
{
var x=document.getElementById('table1').insertRow(currentRow);
var cell0=x.insertCell(0);
cell0.innerHTML="<td><div id='frmName'<b><input name='roomName' value='Room'</b></div></td>"
cell0.colSpan="2";
currentRow+=1;
roomApps=0
}
}I want to take what the user inputs into the text field 'roomName' and use another function addAppliance() to change the innerHTML in the cell to it.

I will also have to access multiple more inputs in other cells so just accessing the last row in the table wouldn't be helpful as far as learning for the rest of the project goes.

if you could offer any help it would be greatly appreciated

full source here:
http://www.filefactory.com/file/a1fgb05/n/Energy_.txt

Kor
12-02-2009, 08:23 AM
innerHTML is not a standard DOM method, even it is cross browser. That means it will not always insert the new created elements nor their properties into the DOM tree. Inserting table's elements is one of these cases. Even Microsoft warns the coders about the innerHTML limits:

"The innerHTML property is read/write for all objects except the following, for which it is read-only: COL, COLGROUP, FRAMESET, HEAD, HTML, STYLE, TABLE, TBODY, TFOOT, THEAD, TITLE, TR"
See:
http://msdn.microsoft.com/en-us/library/ms533897(VS.85).aspx

Google for DOM methods: createElement(), setAttribute(), appendChild()... and so on