The form fields:
<label for="a">Field A:</label> <input id="a" name="a" type="text" value="a value" /> <br/> <label for="b">Field B:</label> <input id="b" name="b" type="text" value="b value" /> <br/> <label for="c">Field C:</label> <input id="c" name="c" type="text" value="c value" />The hookup:
<script> $(function() { $("input").modified( { onModified: valueChanged } ); }); var isPageDirty = false; function valueChanged(id, previousVal, newVal) { isPageDirty = true; alert('The page is dirty. The value for ' + id + ' has changed from ' + previousVal + " to " + newVal); } </script>The jModified Plugin:
(function($){ $.fn.modified = function(options) { var defaults = { onModified: function(id, previousVal, newVal) { alert('The value for ' + id + ' has changed from ' + previousVal + " to " + newVal ); } }; var options = $.extend(defaults, options); this.each(function() { $(this).data('originalValue', $(this).val()); }); return this.change(function() { var newValue = $(this).val(); var originalValue = $(this).data('originalValue'); if(newValue != originalValue) options.onModified($(this).attr("id"), originalValue, newValue); }); }; })(jQuery);
Get the full source on GitHub.