Using jQuery:
var _isDirty = false;
$("input[type="text"]").change(function(){
_isDirty = true;
});
// replicate for other input types and selects
Combine with onunload
/onbeforeunload
methods as required.
From the comments, the following references all input fields, without duplicating code:
$(':input').change(function () {
Using $(":input")
refers to all input, textarea, select, and button elements.