title: Javascript null value
body: <p>Javascript code assigns null value to variable "room".</p>
  
  <pre><code>var room = document.getElementById("roomID").value;
  </code></pre>
  
  <p>is always null</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Echo Chamber&lt;/title&gt;
          &lt;meta charset="UTF-8"&gt;
          &lt;meta name="viewport" content="width=device-width"&gt;
      &lt;/head&gt;
      &lt;body&gt;
  
          &lt;div&gt;
               &lt;label&gt;Room ID:&lt;/label&gt;
              &lt;input type="number" id="roomID"/&gt;&lt;br/&gt;&lt;br/&gt;
               &lt;label&gt;Message :&lt;/label&gt;
              &lt;input type="text" id="messageinput"/&gt;&lt;br/&gt;&lt;br/&gt;
          &lt;/div&gt;
          &lt;div&gt;
              &lt;button type="button" onclick="openSocket();" &gt;Open&lt;/button&gt;
              &lt;button type="button" onclick="send();" &gt;Send&lt;/button&gt;
              &lt;button type="button" onclick="closeSocket();" &gt;Close&lt;/button&gt;
          &lt;/div&gt;
          &lt;div id="messages"&gt;&lt;/div&gt;
  
          &lt;script type="text/javascript"&gt;
  
              var webSocket;
              var messages = document.getElementById("messages");
              var room = document.getElementById("roomID").value;
  
              function openSocket(){
                  if(webSocket !== undefined &amp;&amp; webSocket.readyState !== WebSocket.CLOSED){
                     writeResponse("WebSocket is already opened.");
                      return;
                  }
                  console.log(room);
                  webSocket = new WebSocket("ws://localhost:8080/EchoChamber/echo/" + room);
  
                  webSocket.onopen = function(event){
                      if(event.data === undefined)
                          return;
  
                      writeResponse(event.data);
                  };
  
                  webSocket.onmessage = function(event){
                      writeResponse(event.data);
                  };
  
                  webSocket.onclose = function(event){
                      writeResponse("Connection closed");
                  };
              }
  
              function send(){
                  var text = document.getElementById("messageinput").value;
                  webSocket.send(text);
              }
  
              function closeSocket(){
                  webSocket.close();
              }
  
              function writeResponse(text){
                  messages.innerHTML += "&lt;br/&gt;" + text;
              }
  
          &lt;/script&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/ROdSH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ROdSH.png" alt="enter image description here"></a></p>