Invalid Argument on close bracket (?)

wxdqz

New Member
This simple code from my onLoad event is generating an Invalid Argument; the error appears to be occuring on the for loop close bracket (?):

{
var obj=document;
var names=new Array();
var strnames="";
var i=0;
for (prps in obj) {
names[i++] = prps + ':\t' + obj[prps];
} // for (prps in obj)
}

If I put an alert immediately after the names[i++] assignment, I get the message about 80 times (indicating that the loop and assignment are working correctly). If I put the alert immediately after the for loop close bracket, it never executes and I get the Invalid Argument error. In other words, this:

{
var obj=document;
var names=new Array();
var strnames="";
var i=0;
for (prps in obj) {
names[i++] = prps + ':\t' + obj[prps];
alert("test"); } // for (prps in obj)
}

produces 80 "test" alerts followed by an error. And this:

{
var obj=document;
var names=new Array();
var strnames="";
var i=0;
for (prps in obj) {
names[i++] = prps + ':\t' + obj[prps];
} alert("test"); // for (prps in obj)
}

generates an error and no alert boxes. I know the assignment is working (I've test it with an alert), and the syntax seems flawless (right?).

Also note that if I redefine obj to be the first form in the document (i.e., var obj=document.forms[0]), then I get no errors!

Why on earth is this close bracket causing an error? Or what is causing the error? Any advice is appreciated.

Thanks in advance.
Jeff
 
Back
Top