views:

66

answers:

1

I'm trying to use the jQueryUI Dialog to get user confirmation before a database update, but I'm battling to see how I can tell what the user's choice on the dialog is, as all in samples I can find, both buttons just close the dialog, with no persistence of the chosen button. E.g. from the jQueryUI sample and docs:

            buttons: {
                'Deactivate the campaign': function () {
                    $(this).dialog('close');
                },
                Cancel: function () {
                    $(this).dialog("close");
                }
            }
+3  A: 

Your calling the same function ( $(this).dialog('close'); ) for both buttons. You need to do somehting more than just close the dialog. You can update a hidden span to pass which button was clicked or just call the DB update from there.

buttons: {
        'Deactivate the campaign': function () {
            //pass the value using a hidden span
            $('#myHiddenControl').val('True');

            //or just call the db update
            $.ajax({/* db call code ommited*/});

            $(this).dialog('close');
        },
        Cancel: function () {
            //pass the value using a hidden span
            $('#myHiddenControl').val('False');
            $(this).dialog("close");
        }
}
ctrlShiftBryan
Or you can use AJAX to send the information to the server.
Ikke
Hence the $.ajax()...
ctrlShiftBryan
Thanks @ctrlShiftBryan. I kind of guesses I was usign the same code for both buttons, but even the official samples do that. I suppose the state of open source documentation is at play here.
ProfK