Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 912417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:22:33+00:00 2026-05-15T17:22:33+00:00

I have the following code, and the javascript console in chrome says Can’t read

  • 0

I have the following code, and the javascript console in chrome says “Can’t read innerHTML property of null. Why does document.getElementById(‘display’) turn up empty handed?

<!DOCTYPE html>
<html>
    <head>
        <title>Chat 3</title>
        <script type="text/javascript">
            function showmsg(str){
                var display = document.getElementById('display');
                display.innerHTML += "<p>" + str + "</p>";
            }

            if("WebSockets" in window){
                pass;
            }else{
                showmsg("Your browser doesn't support WebSockets. Try Google Chrome.");
            }
        </script>

        <style type="text/css">
        #username { 
            padding: 0px;
            margin: 0px;
            height: 26px;
            width: 400px;
        }

        /* ADDED container div that wraps onlineusers and display */
        #container {
          margin: 10px 0;
        }

        /* use float: left to put them side-by-side */
        #display { 
            padding: 0px;
            margin: 0px;
            border-style: solid;
            border-width: 1px;
            overflow: auto;
            height: 400px;
            width: 400px;
            float: left;
        }

        #onlineusers { 
            padding: 0px;
            margin: 0px;
            height: 400px;
            width: 200px;
            border-style: solid;
            border-width: 1px;
            float: left;
        }

        /* Added container2 to wrap inputline and sendbutton */
        #container2 {
            margin: 10px 0;
        }

        #inputline { 
            padding: 0px;
            margin: 0px;
            height: 26px;
            width: 350px;
            float: left;
        }

        #sendbutton {
            padding: 0px;
            margin: 0px;
            height: 30px;
            width: 50px;
            float: left;
        }

        /* this is a well used "hack". */
        .clearfix {
          clear: both;
        }
        </style>
    </head>
    <body onload="document.getElementById("username").focus()">
            <input type="text" id="username" />
            <div id="container">
                <div id="display"></div>
                <div id="onlineusers"></div>
                <div class="clearfix"></div>
            </div>

            <div id="container2">
                <input type="text" id="inputline" length="55" />
                <input type="button" id="sendbutton" value="Send" />
            </div>
    </body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T17:22:34+00:00Added an answer on May 15, 2026 at 5:22 pm

    Put your script tag at the end of the document:.
    In your case the page has not been completely parsed into DOM tree, but your script executes anyway:

           <body onload="document.getElementById('username').focus()">
               <input type="text" id="username" />
               <div id="container">
                   <div id="display"></div>
                   <div id="onlineusers"></div>
                   <div class="clearfix"></div>
               </div>
    
               <div id="container2">
                   <input type="text" id="inputline" length="55" />
                   <input type="button" id="sendbutton" value="Send" />
               </div>
    
               <script type="text/javascript">
               function showmsg(str){
                   var display = document.getElementById('display');
                   display.innerHTML += "<p>" + str + "</p>";
               }
    
               if("WebSockets" in window){
                  pass;
               }else{
                   showmsg("Your browser doesn't support WebSockets. Try Google Chrome.");
               }
           </script>
       </body>
    

    This is also considered a good practice for performance reasons:
    http://developer.yahoo.com/performance/rules.html#js_bottom

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Javascript code that works perfectly: $(document).ready(function() { $(#Select1).setDefault(); $(#Select2).setDefault(); $(#Select3).setDefault();
I have the following JavaScript code: oCoord = {x: null, y: null}; var aStack
So I have the following JavaScript code: <script type=text/javascript> function clearRadioButtons() { document.getElementById(radiobutton1).checked=; //etc
I have the following javascript code: if (url.match(/?rows.*?(?=\&)|.*/g)){ urlset= url.replace(/?rows.*?(?=\&)|.*/g,rows=+document.getElementById('rowcount').value); }else{ urlset= url+&rows=+document.getElementById('rowcount').value; }
I have the following Javascript code: function checkIfValid(){ var form = document.createuserform; var valid
I have the following code: Javascript: slideShow = { ImgsFolder: images/, ImgsSrc: ['img.jpg', 'img2.jpg',
I have the following code in JavaScript and jQuery: $(<li />) .html('Some HTML') I
I have the following JavaScript code: var x = ['CFMG','JMFMG','CPMAF']; var y = $.param({'test':x});
I have the following Javascript code. When the page is loaded it is scrolled
I have the following JavaScript code which I like to convert to jQuery but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.