title: Why am I getting "TypeError: Cannot read property 'value' of null" when using getElementById?
body: <p>In the following code:</p>
  
  <pre><code>function Transact() {
      if(document.getElementById('itctobuy').value!='') {
          itctobuy = parseInt(document.getElementById('itctobuy').value);
      }
      if(document.getElementById('steamtobuy').value!='') {
          steamtobuy = parseInt(document.getElementById('steamtobuy').value);
      }
      if(document.getElementById('reltobuy').value!='') {
          reltobuy = parseInt(document.getElementById('reltobuy').value);
      }
      if(document.getElementById('airtobuy').value!='') {
          airtobuy = parseInt(document.getElementById('airtobuy').value);
      }
      if(document.getElementById('bsnltobuy').value!='') {
          bsnltobuy = parseInt(document.getElementById('bsnltobuy').value);
      }
      updateValues();
  }
  </code></pre>
  
  <p>The function's executed by a simple <code>onclick</code> of a button. There are 5 textarea elements and the user may input a number in any, and upon clicking the button the value should be stored in these vars if the textarea value isn't empty (Although it doesn't work even if the empty condition is not present).<br>
  If I remove the entire block, <code>updateValues()</code> executes fine, whereas putting it back causes it not be executed, so the problem's with it. What's the reason for this and how do I fix this?</p>
  
  <p>Edit: The console says the following:</p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot read property 'value' of null at TRANSACT at HTMLButtonElement.onclick</p>
  </blockquote>
  
  <p>So what's the cause of this error? It doesn't work when I input all text fields and their values are not null.</p>