Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically Set Title On Dialog

Tags:

jquery-ui

    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.

like image 928
Kezzer Avatar asked Jan 21 '10 09:01

Kezzer


2 Answers

$("#your-dialog-id").dialog({
    open: function() {
        $(this).dialog("option", "title", "My new title");
    }
});
like image 162
Agorreca Avatar answered Nov 03 '22 13:11

Agorreca


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;
});
like image 34
Natrium Avatar answered Nov 03 '22 13:11

Natrium