Hi All, Can anyone tell me how can i use a varaible foe button text in jquery dialogs . I want to make a dynamic button name.
var buttonName = "something";
$('#button-id').attr('value', buttonName);
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 });
The problem here is that the dialog plugin does not assign an id to its buttons, so it's quite difficult to modify them directly.
Instead, initialise the dialog as normal, locate the button by the text it contains and add an id. The button can then be accessed directly to change the text, formatting, enable/disable it, etc.
$("#dialog_box").dialog({
buttons: {
'ButtonA': function() {
//... configure the button's function
}
});
$('.ui-dialog-buttonpane button:contains(ButtonA)').attr("id","dialog_box_send-button");
$('#dialog_box_send-button').html('Send')
This will work
$($("button", $("#dialogId").parent())[NUMBER_OF_YOUR_BUTTON]).text("My Text");
And don't forget
$($("button", $(".info_dialog").parent())[1]).html("<span class='ui-button-text'>Button text here.</span>");