469,352 Members | 2,154 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

can't get the text from a div, neither when I try to use innerHTML or when I try to walk the DOM


In the function below I use a call to Prototype to get some text from
another webpage and I fill a div with it. You can see the red, narrow
div halfway down this page:

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

You can see the div is full of text. But when I try to get this text, I
get nothing. When I test for childNodes I get zero, and when I try
innerHTML I get nothing. Prototype is suppose to update the innerHTML
of the target div, so that should work, but it is not.

I can see the text on screen, so why am I not able to capture it with
my script?

unction 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?...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...yTagsToGet=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.backgroundCo lor = "#944";
containerForPopularTagsTextArea.style.height = "800px;";
containerForPopularTagsTextArea.style.width = "200px;";

var refToBody = document.getElementById("main");
refToBody.appendChild(containerForPopularTagsTextA rea);

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);
}

Apr 6 '06 #1
2 1268
I mean, its a little surreal. If you go to this page you can see the
red box with text:

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

and yet nothing I do can get the contents of that box:

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);

The box reports having zero childNodes, blank innerHTML and when I try
"value" (a long shot at best) I get 'undefined'. I can see the text
with my eyes, but nothing I do seems able to capture it.

Jake Barnes wrote:
In the function below I use a call to Prototype to get some text from
another webpage and I fill a div with it. You can see the red, narrow
div halfway down this page:

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

You can see the div is full of text. But when I try to get this text, I
get nothing. When I test for childNodes I get zero, and when I try
innerHTML I get nothing. Prototype is suppose to update the innerHTML
of the target div, so that should work, but it is not.

I can see the text on screen, so why am I not able to capture it with
my script?

unction 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?...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...yTagsToGet=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.backgroundCo lor = "#944";
containerForPopularTagsTextArea.style.height = "800px;";
containerForPopularTagsTextArea.style.width = "200px;";

var refToBody = document.getElementById("main");
refToBody.appendChild(containerForPopularTagsTextA rea);

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);
}


Apr 7 '06 #2
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.
Jake Barnes wrote:
In the function below I use a call to Prototype to get some text from
another webpage and I fill a div with it. You can see the red, narrow
div halfway down this page:

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

You can see the div is full of text. But when I try to get this text, I
get nothing. When I test for childNodes I get zero, and when I try
innerHTML I get nothing. Prototype is suppose to update the innerHTML
of the target div, so that should work, but it is not.

I can see the text on screen, so why am I not able to capture it with
my script?

unction 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?...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...yTagsToGet=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.backgroundCo lor = "#944";
containerForPopularTagsTextArea.style.height = "800px;";
containerForPopularTagsTextArea.style.width = "200px;";

var refToBody = document.getElementById("main");
refToBody.appendChild(containerForPopularTagsTextA rea);

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);
}


Apr 7 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Reply Via Newsgroup | last post: by
9 posts views Thread by martymix | last post: by
8 posts views Thread by Pratik Patel | last post: by
9 posts views Thread by art | last post: by
3 posts views Thread by jackson.rayne | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.