Click to See Complete Forum and Search --> : Reference wrong


Webskater
03-03-2003, 12:58 PM
<script>
var CatArray = new Array(2)
CatArray[0] = 25
CatArray[1] = 30
CatArray[2] = 40
</script>
<script>
function CheckCategory(CatID)
{
for (i=0;1<CatArray.length;i++)
{
if (CatID == CatArray[i])
{
Do something
}
}
}
</script>

When I call the function CheckCategory it tells me that CatArray is not an object. How can I refer to it? Thanks for any help.

Eag|e
03-03-2003, 01:04 PM
Don't know if this could be the problem since I've only been using JS for 2 days, but I didn't see CatID mentioned as a variable anywhere cept for in that if/else statement I believe...

Webskater
03-03-2003, 02:04 PM
CatID is passed into the function as a parameter.

khalidali63
03-03-2003, 02:33 PM
Not completely sure,but take a look at this line

for (i=0;1<CatArray.length;i++)

instead if i<CatArray.length,
you have 1<CataArray.length

this should set the infinite loop...

Khalid

Webskater
03-03-2003, 03:13 PM
Thanks khalid
I typed the code into my question here from memory - I only hope when I get into work tomorrow that I did the same thing at work - i.e. typed "1" instead of "i". I find javascript so endlessly frustrating that, when I get an error, I always assume it is because of some arcane naming methodology, and tend to overlook typos! Thanks again.