Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Javascript Error : Object Required

Guest
Jan 02, 2007 Jan 02, 2007
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.
TOPICS
Server side applications
264
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 02, 2007 Jan 02, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 03, 2007 Jan 03, 2007
LATEST
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.
>
>
>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines