Detecting form changes on beforeunload?
<p>This has already been asked, I know, but I don't understand why this isn't working for me.</p>

<p><a href="http://jsfiddle.net/M9tnP/16/" rel="nofollow">http://jsfiddle.net/M9tnP/16/</a></p>

<p>Trying to detect form changes, and if the user tries to navigate away, I want them to confirm that they will lose their changes...</p>

<pre><code>var dirty = false;
$("form#add_item :input").change(function() {
    dirty = true;
});

$("window").on('beforeunload', function() {
    if (dirty) {
        return 'You have unsaved changes! If you leave this page, your changes will be lost.';
    }
</code></pre>

<p>});​</p>
