Pass a function as an argument in jQuery dialog -


i want create dialog function button in dialog call function. not work.
code below //function initial dialog

function inti_dlg(selector, autoopen, height, width, modal, num_button, fn_apply, fn_cancel, fn_close)     {         if (num_button>1)         {             selector.dialog({                 autoopen: autoopen,                 height:height,                 width:width,                 modal:modal,                 buttons:{                     apply:function(){fn_apply},                     cancel:function(){fn_cancel}                 },                 close:function(){fn_close}             });         }         else{             selector.dialog({                 autoopen: autoopen,                 height:height,                 width:width,                 modal:modal,                 buttons:{                     apply:function(){fn_apply}                 },                 close:function(){fn_close}             });         }     } 

//function abc

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

// call initial dialog function

$(function (){     inti_dlg($('#cde'), false, 440, 480, true, 1, abc(), '', abc());     $('#clickhere').click(function(){$('#cde').dialog('open');}); }); 

html :

<div id="clickhere">click here</div> <div id="cde">      <div>test : pass argument function</div> </div> 

http://devlicio.us/blogs/sergio_pereira/archive/2009/02/09/javascript-5-ways-to-call-a-function.aspx

use

function.apply()

function.call()

to call function passed parameter. , don't need add paranthesis along function name pass argument. pass function name.

function inti_dlg(selector, autoopen, height, width, modal, num_button, fn_apply, fn_cancel, fn_close) {     if (num_button>1)     {         selector.dialog({             autoopen: autoopen,             height:height,             width:width,             modal:modal,             buttons:{                 apply:function(){fn_apply.apply()},                 cancel:function(){fn_cancel.apply()}             },             close:function(){fn_close.apply()}         });     }     else{         selector.dialog({             autoopen: autoopen,             height:height,             width:width,             modal:modal,             buttons:{                 apply:function(){fn_apply.apply()}             },             close:function(){fn_close.apply()}         });     } } 

and calling this

$(function (){ inti_dlg($('#cde'), false, 440, 480, true, 1, abc, '', abc); $('#clickhere').click(function(){$('#cde').dialog('open');}); }); 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -