Reputation: 26281
Upon opening a jQueryUI Dialog, I would like to perform a GET request, and based on the response, change the button text. After hours of struggling, I finally got the following working. Is this really the best/only? Thanks
$("#dialog").dialog({
open : function() {
var dialog=$(this);
$.get('ajax.php', function (data) {
var buttons=dialog.dialog( "option", "buttons" );
buttons[1].text=(data==1)?"CANCEL":"CLOSE";
var buttons=dialog.dialog( "option", "buttons" ,buttons);
});
},
buttons : [
{
text : 'SAVE',
click : function() {}
},
{
text : 'CANCEL',
click : function() {}
}
]
});
Upvotes: 2
Views: 2335
Reputation: 3005
You can change the button text like this...
the below given is without ajax
function setbutton(button1, button2) {
var btns = {};
btns[button1] = function() {
//your function
$( this ).dialog( "close" );
};
btns[button2] = function() {
// Do nothing
//your function
$( this ).dialog( "close" );
};
document.getElementById('dialogshow').innerHTML = "<div>open with given button text</div>";
$( "#dialogshow" ).dialog({
autoOpen: true,
width: 450,
height: 200,
modal: true,
position: 'center',
modal: true,
buttons: btns
});
}
$('.test').click(function() {
setbutton('start', 'End');//in here button name you want..
});
Upvotes: 2