jQuery UI-dialog -setting Buttons dynamically and pass values

Discussion in 'jQuery' started by manjuhere, Sep 19, 2013.

  1. #1
    I'm dynamically setting buttons to the jQuery UI dialog like below.


      arrButton = {};
        var i = 0;
        for (i = 0; i < dialog_buttons.length; i++) {
       
            for (var key in dialog_buttons[i]) {
                arrButton[key] = {
                    id: key,
                    text: dialog_buttons[i][key],
                    click: function () {
                        test($('#' + key));
                    }
                };
            }
       
        }
       
        function test(value) {
            if (value.selector == "#confirm") {
                confirmthis();
            }
            if (value.selector == "#cancel") {
                cancelthis();
            }
        }
        $("#" + div.id).dialog({
            modal: true,
            buttons: arrButton
        });
    Code (markup):
    when the button clicked, the key will be the last value from the iteration. Let's say we have keys confirm and cancel then when the button is clicked, the key parameter will be cancel.

    So when I click a button from the dialog, I want to know which button was pressed.

    So when I click a button, I need to know which button I clicked.

    A sample code has been placed in the fiddle below. But im not able to crete a jquery UI dialog here which is working fine in my site.

    http://jsfiddle.net/DOmEl/qNGEw/8/
     
    manjuhere, Sep 19, 2013 IP