views:

1391

answers:

5

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.

+1  A: 
var buttonName = "something";
$('#button-id').attr('value', buttonName);
Jeff Ober
For jQuery dialogs. Not jQuery.
Will Morgan
+6  A: 

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

W. van Kuipers
Tested it? If so, +1.
Will Morgan
yup works like a charm!
W. van Kuipers
A: 

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')       
David Toy
A: 

This will work $($("button", $("#dialogId").parent())[NUMBER_OF_YOUR_BUTTON]).text("My Text");

HeavyWave
A: 

And don't forget

$($("button", $(".info_dialog").parent())[1]).html("<span class='ui-button-text'>Button text here.</span>");
Andrew