Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    document.getElementByID is not a function ??

    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.

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,511
    Thanks
    3
    Thanked 504 Times in 491 Posts
    Code:
    <script>
    function chatMessage(sender, message)
    {
    document.getElementById("chatPanel").innerHTML+= "<b>" + sender + "</b> - " + message + "<br>";
    }
    </script>
    note Id not ID
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    use rather DOM methods instead of innerHTML.

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

    Javascript is case sensitive. see the red character.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •