userak userak - 7 months ago 10
Javascript Question

how to call a function which is passed as parameter in another function

how to call a function which is passed as parameter in another function



here the function i am calling onclick i paased the fucntion name as parameter

onclick="calldialogbox('thisisfortest')"




this is the function which is calling onclick

function calldialogbox(funtion_name){
var dialog = $('<p>Are you sure?</p>').dialog({
buttons: {
"Yes": function(){
dialog.dialog('close');
funtion_name(); //here i am calling function
},
"Cancel": function() {
dialog.dialog('close');
}
}
});
}




this is the function that is i want to call

function thisisfortest(){
alert("thisisfortest");
}

Answer

try this one.
in html

<a onclick="calldialogbox('thisisfortest')">Click Me</a>

js

function calldialogbox(funtion_name){
var dialog = $('<p>Are you sure?</p>').dialog({
    buttons: {
        "Yes": function(){
            dialog.dialog('close');
            funtion_name(); //here i am calling function
        },
        "Cancel":  function() {
            dialog.dialog('close');
        }
    }
});
}

function thisisfortest(){
alert("thisisfortest");
}