document.getElementById().innerHTML fails with 'Unknown Error' in IE

Hello,
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:
<script type=text/javascript>
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.

Thanks.

[1873 byte] By [Lost_Pupp] at [2008-2-14]
# 1
After many hours of testing different methods and routines, I finally was able to make a not so W3C complient method that works as it should. The method works in both FF and IE without error. Additionally this not so W3C complient method works without having to write the entire table elements, rather just the text to be changed. I guess you can't always rely on the documentation.

I no longer need your assistance.

Lost_Pupp at 2007-9-8 > top of Msdn Tech,.NET Development,JScript for the .NET Framework...
# 2
The problem you described above is exactly what I have run into...how

did you solve it exactly? Did you move the element out of the table?

Pleeease let me know :)

Thanks a million!

RyanWilkes at 2007-9-8 > top of Msdn Tech,.NET Development,JScript for the .NET Framework...
# 3
Working on the same problem...

tried

"getElementsByName" (instead of "getElementById")... no luck

tried using

name="myelement" id="myelement" .... no luck

also tried

document.all.getElementById ... no luck

Of course there's no issue in Firefox...., just IE...

geekinout at 2007-9-8 > top of Msdn Tech,.NET Development,JScript for the .NET Framework...
# 4
//Got some code from :
//http://www.permadi.com/tutorial/jsInnerHTMLDOM/index.html
//hope this helps...

if (document.getElementById)
{
var replace=document.getElementById('abc');
if (replace)
{
if (replace.childNodes[0])
{
replace.childNodes[0].nodeValue=thisHtml;
}
else if (replace.value)
{
replace.value=thisHtml;
}
else //if (replace.innerHTML)
{
replace.innerHTML=thisHtml;
}
}
}

geekinout at 2007-9-8 > top of Msdn Tech,.NET Development,JScript for the .NET Framework...
# 5
I am having the same issue, but the code snippet geekinout posted above results in the same error. Has anyone else figured out a different solution?
crpietschmann at 2007-9-8 > top of Msdn Tech,.NET Development,JScript for the .NET Framework...
# 6
In my code, I'm swapping out the content of a DIV element using the innerHTML property. The string of HTML I was assigning the DIV's innerHTML property to contained <FORM> tags. Sometimes (very rarely) it would generate an 'Unknown Error' in IE6. I fixed this error by removing the <FORM> tags from the HTML string I was assigning to the DIV's innerHTML property.
crpietschmann at 2007-9-8 > top of Msdn Tech,.NET Development,JScript for the .NET Framework...
# 7
I'm having the same error. It is caused because I put a <div> into it, but there is no way I can remove it.

someone please help! (it would help if everyone used firefox.....)

dragonfireking at 2007-9-8 > top of Msdn Tech,.NET Development,JScript for the .NET Framework...
# 8
I have the same error. It is caused by a <div> that should be in the <div> in the body, but the <div> I want to insert can't be removed. Can someone help me?

(it would help if everyone used firefox..)

dragonfireking at 2007-9-8 > top of Msdn Tech,.NET Development,JScript for the .NET Framework...
# 9
I have little doubt that there are a hundred ways to cause this problem. Here's what happened to me.

I tried to discover if I even had the right <div> using...

var container = document.getElementById("total");
alert(container.innerHTML);

It came up empty when it shouldn't. So I gave the <div> a name, "name=blah" and tried to see it.

alert(container.name);

The name the alert gave me was "total"!!!!! So I searched through my code to see what else used the name "total." Sure enough, I found something. What my code had was...

...
<input type=hidden name=total value=0>
...
<div id=total name=blah>some text</div>

Brain-dead IE was taking the first item using EITHER the name or ID assigned "total" rather than the ONLY item with an ID of "total." It took me hours to figure this out.

I changed my <div>'s ID to "dangiedivtotal" and re-ran my alert test. Sure enough, everything worked, including the innerHTML assignment.

So, Rule #1: never use the same name for name= or id= in multiple tags assuming IE is smart enough to know the difference between them it isn't. IE's implementation of getElementById looks at **both** the name= and id= references and takes the first one it finds.

WindRiverPublishing at 2007-9-8 > top of Msdn Tech,.NET Development,JScript for the .NET Framework...
# 10
Try removing the div id from the .jsp and create it using javascript:

var z =event.responseText;
var newdiv = document.createElement('div');
newdiv.setAttribute('id','usersSubDiv');
newdiv.innerHTML = z;
var nd = document.getElementById('frame');
nd.appendChild(newdiv);
zvon at 2008-1-16 > top of Msdn Tech,.NET Development,JScript for the .NET Framework...

.NET Development

Site Classified