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;
}
}
> 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
[quoted text clipped - 19 lines]
> //Find > immediately after ID tag
> var IDEnd = curRowString.indexOf(">", IDStart);
Not generally a good assumption to local the end of the id string
> //Get ID value
> var IDVal = curRowString.substring(IDStart+5,IDEnd)
[quoted text clipped - 6 lines]
> //*********** Crashes on line below ***************
> rows[x].innerHTML = newRowString;
In IE this replacement is not guaranteed to work
> }
> }
What I would traverse the DOM element where the ID attribute is located,
and then simply replace the ID attribute.