Okay so I have a page where we are using forms inside an Ajax Tab Container. I am clearing out the form fields when I change between tabs. I want to prompt the user to save any changes that may be on the page. This is working pretty good except that the tab changes before the JavaScript pops up. So if they choose cancel they are already on the new tab. I want them to only change to the new tab when they press OK, and if they click cancel it stays on the current page.
Here is the jQuery I am using for the save prompt.
$(function () {
$(':input').bind('change', function () { setConfirmUnload(true); }); // Prevent accidental navigation away
$('.noprompt-required').click(function () { setConfirmUnload(false); });
$('.buttons').click(function () { setConfirmUnload(false); });
function setConfirmUnload(on) {
window.onbeforeunload = (on) ? unloadMessage : null;
}
function unloadMessage() {
return 'You have entered new data on this page. If you navigate away from this page without first saving your data, the changes will be lost.';
}
window.onerror = UnspecifiedErrorHandler;
function UnspecifiedErrorHandler() {
return true;
}
});
Any help is greatly appreciated. Thanks!