0

In the following code, I am using string literals:

$("#divDialogSave").dialog(
                              {
                                resizable: false,
                                height: "auto",
                                modal: true,
                                autoOpen: false,
                                buttons:
                                {
                                  "Yes": function ()
                                  {

                                  },
                                  "No": function ()
                                  {

                                  }
                                }
                              });

I wanted to replace the text "Yes" and "No" with constants, so I did this:

var TEXT_YES = "Yes";
var TEXT_NO = "No";

$("#divDialogSave").dialog(
                              {
                                resizable: false,
                                height: "auto",
                                modal: true,
                                autoOpen: false,
                                buttons:
                                {
                                  TEXT_YES: function ()
                                  {

                                  },
                                  TEXT_NO: function ()
                                  {

                                  }
                                }
                              });

But the text displayed ends up being the name of the variable instead of the actual text held by the variable. What am I doing wrong?

Johann
  • 27,536
  • 39
  • 165
  • 279
  • This isn't how js objects work. If you want to have the property name of an object be the value of a variable, set it like this: `obj[variable_goes_here] = value;` – Daedalus Jan 28 '14 at 06:04

1 Answers1

1

You'll need to construct and use your options like this:

var options = {
  resizable: false,
  height: "auto",
  modal: true,
  autoOpen: false,
  buttons: {}
}

options.buttons[TEXT_YES] = function(){};
options.buttons[TEXT_NO] = function(){};

$("#divDialogSave").dialog(options);
doctororange
  • 11,670
  • 12
  • 42
  • 58