Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically create text in dialog box

How can I dynamically set the text of the dialog box that I'm opening? I've tried a few different things but they all respond with an empty dialog box.

Here is my current try:

$('#dialog').text('Click on the link to download the file:
'.data); $('#dialog').dialog("open");
like image 228
acedanger Avatar asked Oct 06 '09 15:10

acedanger


3 Answers

For best practice, try putting a div inside your dialog div and appending text to that instead.

<div id="myDialog"><div id="myDialogText"></div></div>

and then setting the text of the internal Div. This make for better separation, so you have

  • a div for dialog manipulation
  • and a div for text display

You can then set the text with

jQuery("#myDialogText").text("your text here");
like image 56
dano Avatar answered Nov 20 '22 23:11

dano


Here is an alternative way of creating dialogs on the fly and setting their messages dynamically:

$('<div></div>').dialog({
    modal: true,
    title: "Confirmation",
    open: function() {
      var markup = 'Hello World';
      $(this).html(markup);
    },
    buttons: {
      Ok: function() {
        $( this ).dialog( "close" );
      }
    }   });  //end confirm dialog

See it in action: http://jsfiddle.net/DYbwb/

like image 12
Chad Kuehn Avatar answered Nov 20 '22 21:11

Chad Kuehn


Use the plus symbol to concatenate strings:

$('#dialog').text('Click on the link to download the file:
' + data);
$('#dialog').dialog("open");
like image 4
Karmic Coder Avatar answered Nov 20 '22 23:11

Karmic Coder