title: Uncaught TypeError: Cannot read property 'addEventListener'
body: <p>I have no idea why this does not work. I've seen similar problems on so but they don't fix the problem </p>
  
  <p>That's the HTML code</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;meta charset="utf-8" /&gt;
          &lt;title&gt;Java Script 2&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
      &lt;div id="loginForm"&gt;
          &lt;form name="userLogin"&gt;
          &lt;input type="text" name="userName" /&gt;
          &lt;input type="password" name="userPass" /&gt;
          &lt;input type="button" name="login" value="Login" /&gt;
          &lt;/div&gt;
          &lt;script src = "question_2.js"&gt;&lt;/script&gt;
          &lt;/form&gt;
      &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and this is the JavaScript</p>
  
  <pre><code>var submit = document.getElementById("login");
  
  if(submit!="null"){
  submit.addEventListener("click",getLogin);
  }
  
   function getLogin(){
      var nameData = "admin";
      var passData = "admin";
      var userName = document.userLogin.userName.value;
      var pass = document.userLogin.userPass.value;
  
  
      if(userName.compareTo(nameData) &amp;&amp; pass.compareTo(passData)){
          replace.textContent("Hello there " + nameData);
      }
      else{
          document.write("Try again");
      }
  }
  </code></pre>
  
  <p>I have to make the page remove the sign in from when it matches the set login and password to remove the form and display a welcome message. When i open the page and go into the console I get the following error</p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot read property 'addEventListener' of
    nullquestion_2.js:4 (anonymous function)</p>
  </blockquote>
  
  <p>It targets the action listener I have set for the button but I have no idea how to fix this.</p>