Kieran Senior
Kieran Senior

Reputation: 18230

Dynamically Set Title On Dialog

    var dlg = $("#dialog").dialog({
      autoOpen: false,
      modal: true,
      buttons: {
        'Update': function() {
          alert(clientCode);
        },
        Cancel: function() {
          $(this).dialog('close');
        }
      }
    });

    $(".edit").click(function() {
      myval = $(this).parent().children('td:nth-child(1)').text();
      dlg.dialog('open');
      return false;
    });

How do I take "myval" and have it as the title of the dialog? I've tried passing it as an argument when doing dlg.dialog('open', myval) and no luck. I've also tried passing it as a parameter but with no luck either. I'm probably doing things in the wrong way, however.

Upvotes: 6

Views: 12122

Answers (2)

Agorreca
Agorreca

Reputation: 686

$("#your-dialog-id").dialog({
    open: function() {
        $(this).dialog("option", "title", "My new title");
    }
});

Upvotes: 8

Natrium
Natrium

Reputation: 31204

create the dialog in the click-event and use this to set title:

something like this:

$(".edit").click(function() {
  myval = $(this).parent().children('td:nth-child(1)').text();

  var dlg = $("#dialog").dialog({
  autoOpen: false,
  title: myval,
  modal: true,
  buttons: {
      'Update': function() {
        alert(clientCode);
      },
      Cancel: function() {
        $(this).dialog('close');
      }
    }
  });

  dlg.dialog('open');
  return false;
});

Upvotes: 4

Related Questions