1

I would like to ask you, how can I dynamicaly create HTML content with using javascript. It means, that I need create simply dojo dialog and than I "tell him" with another js file, which content it can show. Or I have html file, which contains some calling on javascript functions, but it doesnt work. Static tags are showed, but js doesnt render content. It is possible with dojo something like this, because I didnt find something.

Miro

assylias
  • 321,522
  • 82
  • 660
  • 783
Miro
  • 11
  • 1
  • 2

1 Answers1

1

It's pretty easy in dojo to create a dialog and give it some content from javascript on a page. The easiest method I have found so far is to create the dialog in dojo-flavored javascript, then create content in it's containerNode using dojo.create.

dojo.require('dijit.Dialog');

function showDialog() {
  var dialog = new dijit.Dialog({ title: 'Confirmation' });
  dojo.create('div', {
    innerHTML: 'Are you sure you want to do this?'
  }, dialog.containerNode /* the content portion of the dialog you're creating */);
  var div = dojo.create('div', {}, dialog.containerNode);
  dojo.create('a', {
    href: '#',
    innerHTML: 'Yes',
    onClick: function() {
      /* do yes stuff */
    }
  }, div);
  dojo.create('a', {
    href: '#',
    innerHTML: 'No',
    onClick: function() {
      /* do no stuff */
      dialog.hide();
      dojo.destroy(dialog);
    }
  }, div);

  dialog.show();
}
Ryan Ransford
  • 3,224
  • 28
  • 35
  • Thank for your quick reply. And I have one more question, is it possible make sometihing like **var xxx = doCreateHTML(a,b,c)** where "doCreateHTML(a,b,c)" is javascript function where I dynamic create some part of HTML code based on aruments, and than I use **innerHTML: xxx** from your code? Or how can I create this one case? – Miro Mar 01 '12 at 19:10
  • It is certainly possible, but without more information I cannot help you out. You need to flesh that comment out a bit more with your requirements and add a new SO question. I'm not sure if a comment is going to get you your answer. – Ryan Ransford Mar 01 '12 at 19:16
  • My problem is, that I have one html file with html tags and tags. When I put it to dojo dialog as a content, those – Miro Mar 01 '12 at 19:38
  • script tags in innerHTML will not get executed automatically. see: http://stackoverflow.com/questions/2592092/executing-script-elements-inserted-with-innerhtml and http://stackoverflow.com/questions/6789502/running-script-tags-fetched-with-jsonp for some clues on how to proceed. You can probably also look into using dojo.parser.parse() on the specific element but that may be an overkill – Vijay Agrawal Mar 03 '12 at 17:45