title: Javascript/JQuery: how to add keypress/blur event that doesn't trigger twice with alert box? IE only
body: <p>I have an input field that I would like to validate on when the user either presses enter or clicks away from it, for this I use the events <code>keypress</code> and <code>blur</code>. If the input fails validation, an alert box is called.</p>
  
  <p>I noticed that in IE (all versions), if I press enter with invalid input, for some reason both the keypress and blur events are fired (I suspect it's the alert box, but it doesn't do this on FF/Chrome) and it shows two of the same alert box. How can I have it so only one is shown?</p>
  
  <p>EDIT: In FF/Chrome, I now noticed that a second alert box appears when I click anywhere after I try to validate with enter.</p>
  
  <p>Simplified code:</p>
  
  <pre><code>$("#input-field").keypress(function(event) {
      if (event.keycode == 13) {
          event.stopPropagation();
          validate();
          return false;
      }
  });
  
  $("#input-field").blur(function() {
      validate();
  });
  
  function validate() {
      if ($("#input-field").val() == '') {
          alert("Invalid input");
      }
  }
  </code></pre>
  
  <p>EDIT: Ah-ha. Not really a fix but a separate detail I forgot - I need to restore the invalid input to its previously valid value, so when the validate function checks the value again it doesn't fail twice.</p>