title: JavaScript runtime error Unable to get property 'value' of undefined or null reference
body: <p>I'm unable to access the variable in the JS file.</p>
  
  <p>The Validation is working fine when written in the same page. But when I pasted the Validation code to a separate JS file, its not working.</p>
  
  <pre><code>&lt;asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server"&gt;
  
      &lt;script src="Scripts/NewValidation.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;table id="tblUpdateReg"&gt;
          &lt;thead&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      Update Details
                  &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      &lt;div&gt;
                          Username :
                      &lt;/div&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;input type="text" runat="server" id="txtUsername" /&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p>JS file:</p>
  
  <pre><code>function Validate() {
  
      var username= document.getElementById("txtUsername").value;
  
      if (username== "") {
          alert("username Required.");
          return false;
      }
  
  
  
      return true;
  
  }
  </code></pre>
  
  <p>Error:JavaScript runtime error: Unable to get property 'value' of undefined or null reference</p>