jquery - passing javascript to a javascript function -


i pass function javascript executed when user presses 1 of buttons, when press "no" or "yes" buttons on dialog box nothing happens, sits there...no error shows in firebug. if hard code "alert('hi')" dialog button works fine, there must in passing javascript part of function parameters.

how can work? in advance.

heres javascript function:

function confirm_yes_no(xtitle,msg, btn_yes_txt, btn_no_txt, btn_yes_js, btn_no_js) {     var button_yes = btn_yes_txt;     var button_no = btn_no_txt;     var dialog_buttons = {};      dialog_buttons[button_yes] = function(){ btn_yes_js }     dialog_buttons[button_no] = function(){ btn_no_js }      $("#modal_confirm_yes_no").html(msg);     $("#modal_confirm_yes_no").dialog({                 title: xtitle,                 bgiframe: true,                 autoopen: false,                 height: 150,                 width: 300,                 modal: true,                 buttons: dialog_buttons             });      $("#modal_confirm_yes_no").dialog("open"); } 

here's how call function:

confirm_yes_no("print checks", "would print checks now?", "yes", "no", "alert('you clicked yes');", "alert('you clicked no');"); 

if btn_yes_js reference javascript function do:

dialog_buttons[button_yes] = btn_yes_js; 

and likewise btn_no_js.

if instead you're saying btn_yes_js string containing source of js function, , appears - don't that!!

your call should like:

confirm_yes_no("print checks", "would print checks now?", "yes", "no",     function() {        alert('you clicked yes');     },     function() {        alert('you clicked no');     } ); 

i.e. pass in references functions (anonymous functions in example), not strings have passed nasty, horrible, never-ever-use-on-pain-of-death eval() function.

see http://jsfiddle.net/alnitak/wherf/

i'd note code need more work, since whilst you're registering callback handlers, neither of them close down or destroy dialog box.

you'll need more like:

dialog_buttons[button_yes] = function() {     $('#modal_confirm_yes_no').dialog('close').dialog('destroy');     btn_yes_js.call(ctx); } 

i.e. local function closes dialog box cleanly, , then invokes relevant callback function. may wish add own ctx variable become value of this within callbacks.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -