views:

147

answers:

1

I have the following JS:

$('#listeditdialog').dialog('open');

Which opens the following dialog:

$('#listeditdialog').dialog({
    autoOpen: false,
    resizable: false,
    position: ['center',150],
    width: 450,
    open: function(event, ui) {
        $("#listeditdialog").load("/projects/view/tasks/ajax/?listid=" + XXXX);
    },
    close: function(event, ui) {
        $("#listeditdialog").html('<p id="loading"> </p>');
    }
});

My Question is when I use the dialog open function in another JS function, how can I pass a listID variable which I would get fom the click even bind that fired the dialog open func.

Thanks!

+1  A: 

If I understand you right, you want to have data that you have access to when you call $('#listeditdialog').dialog('open') that's available when the open event fires?

Something like this could help:

// where dialog is opened
$('#listeditdialog').data('listID', listIDVarOrSimilar); //assign the ID for later use
$('#listeditdialog').dialog('open')

// dialog definition
$('#listeditdialog').dialog({
    autoOpen: false,
    resizable: false,
    position: ['center',150],
    width: 450,
    open: function(event, ui) {
        var $led = $("#listeditdialog");
        $led.load("/projects/view/tasks/ajax/?listid=" + $led.data('listID'); //use the previously saved id
    },
    close: function(event, ui) {
        $("#listeditdialog").html('<p id="loading"> </p>');
    }
});`

http://api.jquery.com/data/

Dan Heberden