Recognizing DOM add for leave page naviation warning

Recognizing DOM add for leave page naviation warning

away from a page without submitting. I am having issues when the page uses document.add to overwrite radio buttons and textboxes. Everything else works. What doesn't work is when the user clears a textbox or radio button. The way it gets cleared is with document.add. I want to include this segment of code on multiple pages, so it must be dynamic. Here is what I have so far:

  1. var warnMessage = "You have unsaved changes on this page!";

  2. $(document).ready(function() {
  3. $(document).live('change', ':input', function () {
  4.     $('form*').add(function() {
  5.       alert("wassup son");
  6.     });
  7.    window.onbeforeunload = function () {
  8.     if (warnMessage != null) return warnMessage;
  9.     }
  10.   });
  11.   //DOESN'T SHOW WARNING MESSAGE IF SUBMIT BUTTON IS PRESSED
  12.   $('form').submit(function() {
  13.     warnMessage = null;
  14.   });
  15. });