Javascript – document.getElementById().innerHTML fails with ‘Unknown Error’ in IE


I'm trying to use document.getElementById().innerHTML in a JavaScript to change information in a webpage. On FireFox this works as described in the W3C documentation, however, the same method returns 'Unknown Error' in IE. The JavaScript looks like this:

function Change_Info (ID, ROW, VALUE) 
  if (document.getElementById)
       var ntext = "<td width=4\% bgcolor=#FFFFFF>&nbsp;</td><td width=92\% bgcolor=#FFFFFF colspan=2><font face=Arial size=2 color=#5578C4>" + VALUE + "</font></td><td width=4\% bgcolor=#FFFFFF><center>&nbsp</center></td>";
       document.getElementById( ID + "-" + ROW).innerHTML = ntext;
       return false;

The script is called by a MouseOver event like this:

onmouseover='Change_Info("thetag","1","Some Info");

The script would combine ID with a – and then ROW, which, in this example would be, thetag-1. The exact tag does exist in the html document. Using getElementById with the hardcoded tag name, reveils the same error, and the variable method is the prefered one in this situation.

To questions regarding why full html table information is in ntext, for whatever reason nested ID's fail on both FireFox and IE, even though the W3C specification states it should work (obviously both browsers have not fully implimented the W3C specs as persceribed). If someone knows of the way to access and change nested ID's, that works in both FireFox and IE, I'd sure like to know it.

Additionally, as yet I'm only getting this 'Unknown Error' in IE when using innerHTML to change the information. Reading works without error.

Can someone point out where my scripting error is so that I can swap text 'messages' on mouseover events.

Best Solution

IE does not let you add.alter table rows that way. You will need to use DOM Methods removeChild, appendChild, and createElement OR insertRow and insertCell