title: onbeforeunload - bind to selective events
body: <p>I am working on a enterprise application where forms a generated dynamically and we don't have control over the code. Most of the controls in the form have following code associated to them</p>
  
  <pre><code>&lt;select name="s_10_1_1_0"  onchange = 'SWESubmitForm(document.SWEForm10_0,s_5,"","1-E0RHB7")' id='s_10_1_1_0' tabindex=1997 &gt;
  
  &lt;input type="text" name='s_10_1_11_0' value=''  onchange = 'SWESubmitForm(document.SWEForm10_0,s_7,"","1-E0RHB7")' id='s_10_1_11_0' tabindex=1997  maxlength="30"&gt;
  </code></pre>
  
  <p>We would like to present an ok cancel dialog when user tries to navigate to some other page using the link in the header or footer.</p>
  
  <p>I have used to following code to bind onbeforeunload event and present an ok cancel dialog to user.</p>
  
  <pre><code>//this identifies the unique page name
  var viewName = $('input[name="SWEView"]').val(); 
  // if I am on desired page bind the event so that now dialog is presented to user
   if(viewName == "XRX eCustomer Create Service Request View"){
       $(window).bind('beforeunload', function(){
       return 'Your Inquiry has not been submitted yet.';
  });
   }
  </code></pre>
  
  <p>But the problem is that this dialog comes every time user changes a value of any field in the form (I believe that is due to SWESubmitForm code present for onchange event).</p>
  
  <p>I would like to onbeforeunload dialog to come if user clicks any other link outside form or in other words tie onbeforeunload to selective events (including closing the window) on the page.</p>
  
  <p>Please Help</p>