473,403 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

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 1360
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Reply Via Newsgroup | last post by:
Folks, Say I have a table, ten columns, ten rows - Each with a word in it. I want to change the values of some/all of the cells in the table via a hyperlink. How do I reference each cell and...
4
by: Yuk Cheng | last post by:
<<<start index.htm>>> <html> <head> <script> function perform(action){ } </script> </head>
10
by: VictorG | last post by:
Hello, I am new to JS and am trying to add some HTML into a JS function. So that when called the script as well as the HTML will be invoked. Is there some type of embed mechanism, sort of the...
3
by: Alex | last post by:
Hello. First, with AJAX I will get a remote web page into a string. Thus, a string will contain HTML tags and such. I will need to extract text from one <span> for which I know the ID the inner...
9
by: martymix | last post by:
simple question: I have a simple <dt>test text</dt> I get the innerHTML of that dt, and I try and append some text to it like so: dt = document.getElementsByTagName('dt') var text =...
8
by: Pratik Patel | last post by:
Hello, I used innerHTML to assign HTML content. but in my HTML page content have also some javascript function and it will run when page load. bu when HTML code assgin thru innerHTML then this...
9
by: art | last post by:
Hi, We have some scripts here where we use some AJAX to populate some of the page. Basically the AJAX routine calls a PHP script. That PHP script uses a bunch of ECHO statements to create...
3
by: jackson.rayne | last post by:
Hello, Another newbie question here. Let me explain my situation first. I have bought a 3rd party tool that runs a PHP script and gives me some HTML code which I can directly use in my...
5
by: thatcollegeguy | last post by:
Below are my 3php and 2js files. I create a table using ajax/php and then want to change the values in the tables add(+ number for teamid) id's for each specific td in the table. I don't know...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.