1

I have a window.onbeforeunload check for dirty form that works well.

window.onbeforeunload = function () {
    'use strict';
    if (isDirty === 1) {
        return 'You have unsaved changes';
    }
};

I would like to call this when users click on a tab, our tab call look like the following

<li><a href="#scheduling-tab" onclick="return schedulingTabGet('CRFilingScheduling.do', null);">Scheduling</a></li>

The schedulingTabGet code is in another file it is as follows:

function schedulingTabGet(url, formId) {
    return getTab('#scheduling-tab', url, formId);
}

function getTab(tabId, url, formId) {
    jQuery.get(url, jQuery(formId).serialize(), function (data) {
        jQuery(tabId).html(data);
    });

    return false;
}

I tried the code sample from JQuery onchange in tabs event but it wouldn't work. I am not sure if that is a little different case. Any suggestions?

Thanks,

Tom

Community
  • 1
  • 1
Zirous Tom
  • 175
  • 10
  • 25
  • Are you using the jQuery UI Tabs widget? That's what the answer i the other question requires. – Barmar Feb 14 '14 at 20:57
  • Yes I think we are using jQuery-ui-1.9.0. We include the following two files in the code jquery-ui-1.9.0.custom.min.js, and custom-plugins-jquery-ui-1.9.0-compatible.js. – Zirous Tom Feb 14 '14 at 21:05

1 Answers1

0
function checkDirty () {
    'use strict';
    if (isDirty === 1) {
        return 'You have unsaved changes';
    }
};

window.onbeforeunload = checkDirty;

function schedulingTabGet(url, formId) {
    var msg = checkDirty();
    if (msg && confirm(msg)) {
        return getTab('#scheduling-tab', url, formId);
    }
}
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • I tried this out but it didn't work. The schedulingTabGet and the getTab are in a separate file from the main jsp. If I move it into the one jsp it would work. – Zirous Tom Feb 14 '14 at 21:20