osmanraifgunes
osmanraifgunes

Reputation: 1468

converting a click function to call function

I know this topic is asked before but they were not about jqueryui. Therefore I couldn't be sure will they work on my code. I have a pop up that is called from different components. But I have to write a click function for each call. I want to convert it to ca function that I can call it. My script is:

 <script type="text/javascript">
        $(document).ready(function () {
            $('a#popup').live('click', function (e) {

                var page = $(this).attr("href")

                var $dialog = $('<div id="silmeIframe"></div>')
                .html('<iframe  style="border: 0px; " src="' + page + '" width="500px" height="500px"></iframe>')
                .dialog({
                    autoOpen: false,
                    modal: true,
                    height: 'auto',
                    resizable: 'false',
                    width: 'auto',
                    title: "Silmeyi onaylıyor musunuz?",
                    close: function (event, ui) {

                        __doPostBack('<%= btnRefresh.ClientID %>', '');
                    }
                });
                $dialog.dialog('open');
                e.preventDefault();

            });

        });
    </script>

Now, I want it work like

<a onclick="NewFunctionName(parameter1,parameter2,,parameter3)">click<a/>

Upvotes: 0

Views: 185

Answers (1)

Joseph
Joseph

Reputation: 119827

single handler, multiple targets attachment

$(function () {

    function handler(e,param1,param2...) {
        var page = $(this).attr("href")
        ...
        $dialog.dialog('open');
        e.preventDefault();
    }

    //write attachments
    $('a#popup1').on('click',function(e){
        handler(e,param1,param2...);
    });
    $('a#popup2').on('click',function(e){
        handler(e,param1,param2...);
    });
    $('a#popup3').on('click',function(e){
        handler(e,param1,param2...);
    });
});

or single handler, multiple targets in one query

$(function () {
    $('a#popup1, a#popup2, a#popup3').on('click',function (e) {
        var page = $(this).attr("href")
        ...
        $dialog.dialog('open');
        e.preventDefault();
    });
});

Upvotes: 1

Related Questions