Prototype: I'm unable to get the text from a div - I've used both innerHTML and DOM access methods, yet neither work

If you go to this page and scroll down a bit:

http://www.accumulist.com/index.php?whatPage=addAnEntry.php

You'll see a red box with text in it. The box is narrow and tall. You can see the text with your eyes. This box is created dynamically, as you can see in the code below.

When I try to get the contents of the box, I get nothing. I've tried using innerHTML and I get a blank. I've also tested for childNodes and I get zero. You can see the zero and the blank in the final alert() that I call. What might be the right way to access the contents of this box?

Here is the function I call on the page:



function getPopularTagsFromAccumulist() {
  // 04-06-06 - when people enter a new item into Accumulist.com or Mp3Classifieds.com we want
  // the form to auto-suggest to them what some likely categories might be. So, for instance,
  // on this page:
  //
  // http://www.accumulist.com/index.php?whatPage=addAnEntry.php
  //
  // where the visitor might type in "General Category" we want to suggest something in the same
  // way that flickr and del.icio.us do.
  //
  // The first step in the process is to get the most popular tags in the Accumulist database. We
  // will use Prototype to fetch this info for us from this page:
  //
  // http://www.accumulist.com/output.php?whatPage=showTagCloudWithCommas&howManyTagsToGet=200
  //
  // but even before that, we must create a place where the result can be stored. We don't need
  // to make this container visible on screen.
 
  var containerForPopularTagsTextArea = document.createElement("div");
  containerForPopularTagsTextArea.id = 'output-div';
  containerForPopularTagsTextArea.style.backgroundColor = "#944";
  containerForPopularTagsTextArea.style.height = "800px;";
  containerForPopularTagsTextArea.style.width = "200px;";
 
  var refToBody = document.getElementById("main");
  refToBody.appendChild(containerForPopularTagsTextArea);
 
  var url = "http://www.accumulist.com/output.php";
  var pars = 'whatPage=showTagCloudWithCommas&howManyTagsToGet=200';
  var target = 'output-div';
  var myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: pars});
 
  var refToTagDiv = document.getElementById("output-div");
  var nodeNumber = refToTagDiv.childNodes;
  var contentsOfContainer = refToTagDiv.innerHTML;
  var containerValue = refToTagDiv.value;
  alert ("the number of nodes: " + nodeNumber.length + " and the wrods: "   + contentsOfContainer  + containerValue);
}






lkrubnerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lkrubnerAuthor Commented:
Okay, I figured this one out myself - I was looking for the answer before the answer had returned from the server. With this asynchronous stuff, it is important to make sure the call to the server has returned, before you go looking for some value.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Michel PlungjanIT ExpertCommented:
You may ask for a delete and refund here: http://www.experts-exchange.com/Community_Support/
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.