aporat
aporat

Reputation: 5932

jquery ui dialog global variable

I'm tring to create a jquery ui dialog without having a empty div container for the dialog in the HTML. For some reason, the global variable isn't recognized in other javascript functions (besides the original javascript function).

var $signOutDialog = null;


function createDialog() {
    var $signOutDialog = $("<p></p>").dialog({
        resizable: false,
        title: 'Sign Out',
        width: 830,
        autoOpen: false,
        modal: true,

    });
}

and then i have another javascript function which gets called as a result of a $.ajax success delegate. the $signOutDialog global variable is NULL in this function.

 function test2() {
     $signOutDialog.dialog('close'); 
 }

any known solution for closing a jquery ui dialog without having the dialog as an empty html element?

Upvotes: 1

Views: 1563

Answers (2)

Alex
Alex

Reputation: 1722

Remove the var before $signOutDialog in the function, you define it again in the function as a local variable in the function's scope.

Upvotes: 2

Nettogrof
Nettogrof

Reputation: 2136

the global $signOutDialog is a regular javascript variable.

The $signOutDialog inside the createDialog, is a different than the previous one.

so in the test2 method, it try to ".dialog('close')" on a null.

Upvotes: 1

Related Questions