How to detect textarea or input type="text" editing?
<p>I use this snippet to prevent the user from accidentally navigating away from the editing page:</p>

<pre><code>var warning = false;
window.onbeforeunload = function() {
  if (warning) {
    return '';
  }
}
</code></pre>

<p>Now I want to set the variable warning to be true if any of the textarea or input type="text" has been modified, I want to use the onkeyup event such as in:</p>

<pre><code>document.getElementById('textarea_id').onkeyup = function() {
    warning = true;
}
</code></pre>

<p>But it's not working. Don't quite want to use jQuery on this. Any insights?</p>

<p><strong>Update:</strong></p>

<p>Changed to this:</p>

<pre><code>var warning = false;
window.onbeforeunload = function() { 
  if (warning) {
    return 'You have unsaved changes.';
  }
}
document.getElementById('textarea_id').onkeyup = function() {
    warning = true;
}
</code></pre>

<p>Yet it's still not working.</p>

<p>By the way, it's put in  in the  of the page. There are no javascript anywhere else. </p>
