Search code examples
javascriptjqueryjquery-uijquery-pluginsjquery-ajaxq

jQuery, allow only once to click on dialogue yes button


I am trying to write a jQuery dialogue box, when I click on the 'OK' button the data will be sent every time I click on it.

So, I need it to work only once whether I click it many times or once on 'ok' button.

$.dialogue({
                    class: 'big',
                    body: html,
                    yes: {
                        text: 'ok',
                        func: function() {

                            //execute some codes

                    }, //end function
                    },
                    no: {text: 'Cancel'},
                });

Solution

  • $.dialogue({
                        class: 'big',
                        body: html,
                        yes: {
                            text: 'ok',
                            func: (function() {
                                var executed = false;
                                return function () {
                                if (!executed) {
                                executed = true;
                                //execute some codes                                                            
                            }
                            };
                        })(), //end function
                        },
                        no: {text: 'Cancel'},
                    });