title: saving to localstorage onkeyup
body: <p>I am trying to save form data to localstorage on keyup event with javascript. I have the following code but I get the error "Uncaught TypeError: Cannot set property 'onkeyup' of null".</p>
  
  <p><strong>html</strong></p>
  
  <pre><code>&lt;input type="text" id="username" /&gt;
  </code></pre>
  
  <p><strong>javascript</strong></p>
  
  <pre><code>var user = document.getElementById("username");
  user.onkeyup = function(){
      localStorage.setItem('user', user.value);
  };
  </code></pre>