1

jquery-ui dialog window in javascript:

$( "#dialog-confirm" ).dialog({
            resizable: false,
            height:140,
            modal: true,
            buttons: {
                "Ok": function() {
                    $( this ).dialog( "close" );
                },
                "Cancel": function() {
                    $( this ).dialog( "close" );
                }
            }
        });

There two buttons "Ok" and "Cancel". On each button there function. Buttons names fastened hardly. There some ways to named buttons from variable?? like this:

var Button1 = "Ok";
var Button2 = "Cancel";
$( "#dialog-confirm" ).dialog({
            resizable: false,
            height:140,
            modal: true,
            buttons: {
                Button1: function() {
                    $( this ).dialog( "close" );
                },
                Button2: function() {
                    $( this ).dialog( "close" );
                }
            }
        });

I try code above but buttons appear with names "Button1" and "Button2". Can I also display images in buttons but not text???

1 Answer 1

11

Referring to http://jqueryui.com/demos/dialog/ you can see there are 2 alternate ways of defining the buttons, one is what you are using here, the second is using arrays.

var button1 = 'Ok';
var button2 = 'Not Ok';    
$( ".selector" ).dialog({ buttons: [
    {
        text: button1,
        click: function() { $(this).dialog("close"); }
    },
    {
        text: button2,
        click: function() { $(this).dialog('close'); }
    }
] });

It looks like this must solve your problem.

Sign up to request clarification or add additional context in comments.

3 Comments

Can I also from variable set the title bar name of dialog window in javascript?? not in tags by set title="".
@darien-fawkes you can set the title from a variable within the options you pass to the dialog.
This did not work for me, I assume because I am using an older version of jQuery UI (1.7.2). This was the solution that worked for me: stackoverflow.com/questions/1357281/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.