jQuery UI dialog button text as a variable

Nishima picture Nishima · Sep 23, 2009 · Viewed 58.4k times · Source

Can anyone tell me how can i use a variable for button text in jQuery UI dialog? I want to make a dynamic button name.

Answer

W. van Kuipers picture W. van Kuipers · Oct 29, 2009

This won't work because of the way jQuery handles the button name (can be with or without quotes)

This will work:

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 });