Javascript problem with innerHTML -
08-31-2007
, 10:28 AM
I am having trouble with the following function. I am trying to change the
ID of a hidden form object inside a table row. I have used alert() to test
where it breaks and it seems to be on the last line of the function where I
am trying to place the new text back into the table row. Anyone any ideas
where I'm going wrong as I'm not a great Javascript coder. Or even if you
know a better way to carry out what I am trying to do.
Thanks in advance.
this.onDrop = function(table, droppedRow) {
var rows = table.tBodies[0].rows;
var rowsCount = parseInt(rows.length);
for (var x = 0; x <= rowsCount - 1; x++)
{
//Get string contents of row
var curRowString = rows[x].innerHTML;
//Find where ID tag is
var IDStart = curRowString.indexOf("ID");
//Find > immediately after ID tag
var IDEnd = curRowString.indexOf(">", IDStart);
//Get ID value
var IDVal = curRowString.substring(IDStart+5,IDEnd)
//Replace old ID with new ID
var oldID = "ID" + IDVal;
var newID = "ID" + (x+1);
var newRowString = curRowString.replace(oldID, newID);
//*********** Crashes on line below ***************
rows[x].innerHTML = newRowString;
}
} |