saving to localstorage onkeyup
<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>javscript</strong></p>

<pre><code>var user = document.getElementById("username");
user.onkeyup = function(){
    localStorage.setItem('user', user.value);
};
</code></pre>
