...

View Full Version : document.getElementByID is not a function ??



agentforsythe
09-05-2006, 05:32 PM
I'm really tearing my hair out, please help.

I have...

<div id ="chatPanel"></div>

I have a function in the <HEAD>:

<script>
function chatMessage(sender, message)
{
document.getElementByID("chatPanel").innerHTML+= "<b>" + sender + "</b> - " + message + "<br>";
}
</script>

When I call chatMessage("me","some stuff"), the javascript console informs me that document.getElementByID is not a function!

but...

<button onClick="document.getElementById('chatPanel').innerHTML+='BOOM!'">BOOM!</button>

appends to the div just fine when you click the button.

So confused, please help.

vwphillips
09-05-2006, 05:48 PM
<script>
function chatMessage(sender, message)
{
document.getElementById("chatPanel").innerHTML+= "<b>" + sender + "</b> - " + message + "<br>";
}
</script>

note Id not ID

Kor
09-05-2006, 10:42 PM
use rather DOM methods instead of innerHTML.

Anyway getElementById() is not a function, is a method.

Javascript is case sensitive. see the red character.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum