title: How can I check the new value of a text field on keypress?
body: <p>I have a single form field and I need to be able to detect when the field changes and execute some additional code using the <strong><em>new</em></strong> value of the field. I only want to execute the code if the key pushed actually changes the value of the text box. Here's the solution I came up with.</p>
  
  <pre><code>function onkeypress(e) {
    var value = this.value;
    // do something with 
  }
  
  function onkeyup(e) {
    if ( e.which == 8 || e.keyCode == 46 ) { // delete or backspace keys
      this.onkeypress(e);
    }
  }
  </code></pre>
  
  <p>There's just one problem though. onkeypress is fired before the field's value is updated, so when I grab the value, I'm getting the previous value. I would use keyup exclusively if I knew a way to test whether the key changed the value or not, but some characters (like the arrow keys) have no effect on the field's value.</p>
  
  <p>Any ideas?</p>