1

Here is my code for JQuery UI modal window:

$('<p>Message</p>').dialog({
    modal: true,
    buttons: {
      Ok: function() {
         $( this ).dialog( "close" );
      }
    }
});

How can I pass a variable instead of constant string (see Ok above)

isNaN1247
  • 17,793
  • 12
  • 71
  • 118
Nick
  • 15,765
  • 5
  • 22
  • 15

2 Answers2

1

from jQuery UI dialog button text as a variable

var button_name = 'Test';    
var dialog_buttons = {};

dialog_buttons[button_name] = function(){ 
    closeInstanceForm(Function); 
}    
dialog_buttons['Cancel'] = function(){ 
   $(this).dialog('close'); 
}

$('#instanceDialog').dialog({ 
    buttons: dialog_buttons 
});
Community
  • 1
  • 1
balexandre
  • 73,608
  • 45
  • 233
  • 342
1

try this:

var dynamicButtons= {};
var buttonOne = 'Press Me Please!';
var buttonTwo = 'No way';
dynamicButtons[buttonOne] = function() {
    // do your stuffs
};
dynamicButtons[buttonTwo] = function() {
   // do your stuffs
};
$('<p>Message</p>').dialog({
    modal: true,
    buttons: dynamicButtons
});

demo: http://jsbin.com/omawu4/2/

Anas Nakawa
  • 1,977
  • 1
  • 23
  • 42