Sequential dialog execution in JQuery -


i'm trying use jquery dialog confirm removing of different records different tables, it's div being referenced different places in code (reusing dialog confirm different operation). i'm using example: http://jqueryui.com/dialog/#modal-confirmation

since every call, has confirm different action, can't put code execute inside callback ok or cancel buttons of dialog option buttons{}

i have vb's msgbox return value indicating button pressed (whether 'ok', 'accept' or 'close'...). this:

if ( $(target_dialog).dialog('open') == 'ok'){     // awesome }else if( $(target_dialog).dialog('open') == 'cancel') {     // not awesome } 

thanks help.

edit: it's js confirm() example here( http://www.w3schools.com/js/tryit.asp?filename=tryjs_confirm ), don't want pop up, customizable , flexible jqueryui dialog.

edit2: @vishwanath suggests

$("#dialog-confirm").dialog({ //height, modal, width... settings buttons : {     "ok": function() {          // here magic             action = $(this).data('action');         var actiontoperform = actions[action];         actiontoperform.call(this);         // end of magic         $( ).dialog( 'close' );     },      cancel: function() {         console.log("non awesome stuff here");         $( ).dialog( 'close' );     } } });   var actions = { action1 : function(){     console.log(''do action1 stuff here); },  action2 : function(){     console.log('do action2 stuff here'); } // , on... } 

and different parents different actions different answers can performed.

$( '#dlgconfirm' ).data('action', 'action1').dialog( 'open' ); 

thanks.

a possible solution use custom options of jquery ui.

as per following create mode custom option, set dynamically @ time of dialogue creation. check option in click handler , use mode pick right action depending upon mode.

var mode = 'edit'; //set dynamically $("#dialog-confirm").dialog({     height : 140,     modal : true,     mode : mode,     buttons : [ {         text : "ok",         click : function(event) {             var mode = $("#dialog-confirm").dialog('option', mode);             var actiontoperform = actions[mode];             actiontoperfom.call(this, event);         }     },      {         text : "cancel",         click : function(event, ui) {             console.log("non awesome stuff here");         }     } ] });   var actions = {     edit : function(){         console.log(''do edit stuff here);     },      delete : function(){         console.log('do delete stuff here');     }  } 

Comments