May 12, 2010

execute javascript method after completing code behind method?

Question by James123

I want execute below callback() method after completion of document.getElementById('btnDownload').click(); method . Now callback()executing immediatly. I want wait “Click()” process done then Execute callback(); method.

function LoadPopup() {
        //  find the popup behavior
        this._popup = $find('mdlPopup');
        // show the popup
        this._popup.show();

        // synchronously run the server side validation ...
        document.getElementById('btnDownload').click();
       callback();         
    }

 function callback() {
        this._popup = $find('mdlPopup');
        //  hide the popup
        this._popup.hide();
        alert("hi");

}

Answer by Starx

Your question is not clear. But I will give you a example.

For example, you wan to load a page by clicking on a image then after the page load is complete you want to do something you can something like this

$('#buttonid').click(function() {
    //this is the callback function of click event
    //if you want some other callback functions then you need something like this
    $("#somediv").load("page.php", function() {
       //callback function code of .load event
       alert('page loaded');
       });
 });

What you are asking is to have a callback function inside the default callback function of click event and a bit impossible from my point of view.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!