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 8 of 8
  1. #1
    New Coder
    Join Date
    Jul 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    innerHTML posting an error

    Hello forum:

    Being new to Javascript this may seem a silly question for the experts; however, please humor me

    Can anyone tell me what is "technically" wrong with this code:


    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="./styles/vmstyle.css" rel="stylesheet" type="text/css">
    <link href="./styles/vmgrid.css" rel="stylesheet" type="text/css">
    <link>
    <script src="./includes/vmfunctions.js" type="text/javascript"></script>
    </head>
    <body>
    <script>
    function vmGrid_buildDataSet(){
    //getHTTPObject Function Defined In vmfunctions.js
    var http = getHTTPObject();
    http.onreadystatechange=function(){
    if(http.readystate==4 && http.status==200){
    document.getElementByID("testDiv").innerHTML = http.responseText;
    }
    }
    http.open('GET',"cptbrwld.php",true);
    http.send(null);
    }
    </script>
    <div id="testDiv"></div>
    <script>vmGrid_buildDataSet();</script>
    </body>
    </html>

    ------------------------

    The problem I am getting is that Javascript is throwing an error on the assignment of the innerHTML line (Object does not support this property or method). I am pulling my hair out here. Thanks.

    Shawn S.

  • #2
    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
    "technically" u could have used an event, onload for instance, instead of calling the function directly

    <script type="text/javascript">
    function vmGrid_buildDataSet(){
    //getHTTPObject Function Defined In vmfunctions.js
    var http = getHTTPObject();
    http.onreadystatechange=function(){
    if(http.readystate==4 && http.status==200){
    document.getElementByID("testDiv").innerHTML = http.responseText;
    }
    }
    http.open('GET',"cptbrwld.php",true);
    http.send(null);
    }
    onload=vmGrid_buildDataSet;
    </script>

    and remove the
    <script>vmGrid_buildDataSet();</script>
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New Coder
    Join Date
    Jul 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey KOR:

    I'm using a function becuase the data is dynamic and the function will be called multiple times based on user input. I was able to figure out what was going on - a document.write fires a document.open, thus the data page shows. using a div container and populating the innerHTML worked much better; however, I've read that using the innerHTML approach is not considered "good programming practice." Could someone elaborate? Thanks.

    Shawn

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts

    Javascript is case-sensitive

    The error is in red.
    Code:
    document.getElementByID("testDiv").innerHTML = http.responseText;
    It should be document.getElementById.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    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
    gee.. I have not seen that... good eye, glenngv...
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Using innerHTML works reasonably well on all modern (and many not so modern0 browsers. It is 100000% better than using document.write and is more appropriate than using the proper DOM calls if the content you are trying to insert already has HTML tags in it.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #7
    New Coder
    Join Date
    Jul 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Stephen, thanks for your reply. I appreciate any information and input while I am on the up-side of this learning curve.

    Shawn

  • #8
    New Coder
    Join Date
    Jul 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv
    The error is in red.
    Code:
    document.getElementByID("testDiv").innerHTML = http.responseText;
    It should be document.getElementById.

    Glennvg- Thanks for the response- I knew I was studying it too hard. Thanks for entertaining such a trivial question.

    Shawn


  •  

    Posting Permissions

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