greenpool
greenpool

Reputation: 561

how to close a JQuery dialog?

I've got the following dialog which loads displayRecords.php. I've got the close button on the dialog but I'm struggling to get it to work.

$(document).ready(function() { 

     var dlg=$('#ticketDetails').dialog({
        title: 'Ticket Details',
        resizable: false,
        autoOpen:false,
        modal: true,
        hide: 'fade',
        buttons:{ "Close": function() { $(this).dialog("close"); } },
        close: function(e, i) { $(this).hide(); },
        width: 1300


     });


    $('a.view').click(

    function(e) 
    {    

         dlg.load('displayRecord.php?id='+this.id, function(){ 
         dlg.dialog('open');

     });

    });

});

I'm rather new to JQuery. Can someone please point out what looks wrong in the above?

Upvotes: 1

Views: 1809

Answers (1)

chris
chris

Reputation: 36937

var dlg = '';
$(document).ready(function() { 

     dlg=$('#ticketDetails').dialog({
        title: 'Ticket Details',
        resizable: false,
        autoOpen:false,
        modal: true,
        hide: 'fade',
        buttons:{ "Close": function() { $(this).dialog("close"); } },
        close: function(e, i) { $(this).hide(); },
        width: 1300   
     });


    $('a.view').click(

    function(e) 
    {    

         dlg.load('displayRecord.php?id='+this.id, function(){ 
         dlg.dialog('open');

     });

    });


 $('a.closeDialog').click(function(){dlg.dialog('close');});
});

A couple minor adjustments, that may work in concept. The idea I am giving is declaring dlg outside of the function as a global variable of sorts, that the remaining functions can reuse

Upvotes: 2

Related Questions