Skip to main content
January 3, 2007
Question

Javascript Error : Object Required

  • January 3, 2007
  • 2 replies
  • 270 views
the title sums it up....

I'VE DONE
-----------------------------------------------------------------
searched the forum, didn't find anything to solve my problem and with google this seems to be a symptom for many problems, no luck there either.

there isn't really any component i can play with to troublshoot, it's syntax related.

MY SETUP:
--------------------------------------------------
I'm using javascript and reading an XML document. using a for loop, i display all the nodes in the XML and print to the page.

MY PROBLEM:
-----------------------------------------------------------------
i get the following annoying error after page load:
Line: 239
Char: 5
Error: "Object Required"
Code: 0
URL: www.blah.com


i've pasted the related code.

line "239", the error is indicated.


novice web programmer, greatly appreciate any pointers, directions, tips, tricks, workarounds etc.
This topic is closed to new replies. Start a new post to keep the conversation going.

2 replies

Inspiring
January 3, 2007
DanM. wrote:

> SIMPLIFIED QUESTION:
> ------------------------------------------------------------------
>
> in short, why is this illegal?
>
> var titleArray = new Array();
> for (var x = 0; x < 20; x++) {
> //BELOW IS LINE 239, THE ERROR****************
> titleArray = news.childNodes(x).firstChild.text;


var titleArray = new Array();
for (var x = 0; x < 20; x++) {
var TEXT;
if(TEXT=news.childNodes.item(x).firstChild.data){
if (TEXT.nodeType == 1){
titleArray.push(TEXT);
}
}

You may be grabbing white space or another <tag>, not text nodes. And
hard coding the loop max can be a problem too, unless you know there are
exactly 20.
for (var x = 0; x <news.childNodes.length ; x++)

Mick

> }
>
> because i commented out everything but those lines, and still got the same
> error.
>
>
>
January 3, 2007
SIMPLIFIED QUESTION:
------------------------------------------------------------------

in short, why is this illegal?

var titleArray = new Array();
for (var x = 0; x < 20; x++) {
//BELOW IS LINE 239, THE ERROR****************
titleArray = news.childNodes(x).firstChild.text;
}

because i commented out everything but those lines, and still got the same error.