title: Activating OnBeforeUnload ONLY when field values have changed
body: <p>What I'm trying to achieve is to Warn the user of unsaved changes if he/she tries to close a page or navigate away from it without saving first. </p>
  
  <p>I've managed to get the <code>OnBeforeUnload()</code> dialog to pop-up... but I don't want it to be displayed at all if the user hasn't modified any field values. For this, I'm using this hidden input field called <strong>is_modified</strong> that starts with a default value of <strong>false</strong> and flips to <strong>true</strong> when any field is edited. </p>
  
  <p>I tried to bind the <strong>change</strong> event to this is_modified field to try and detect for value change... and only then activate OnBeforeUnload.</p>
  
  <pre><code>$( '#is_modified' ).change( function() {
      if( $( '#is_modified' ).val() == 'true' )
          window.onbeforeunload = function() { return "You have unsaved changes."; }
  });
  </code></pre>
  
  <p>But from what I figure is that the <code>change()</code> event works only after these 3 steps -  a field receives focus, a value is changed and the field looses focus. In case of the hidden input field, I'm not sure how this receiving and loosing focus part works! Hence, the onbeforeunload function is never being activated.</p>
  
  <p>Can anyone suggest a way to maintain a trigger over is_modified?</p>
  
  <p>Thanks.</p>