Click to See Complete Forum and Search --> : Object array


tallalex85
10-05-2007, 07:28 AM
Hello,

I've got a javascript calling a method on a Java applet and on some pages the applet is displayed twice with the same name, I therefore need to check if there's an array of that object so that I can either preform the action on one or both of them. The current code is:


if (document.equation1.length)
{
document.equation1[0].setBackgroundColor('#ffffff');
document.equation1[1].setBackgroundColor('#ffffff');
} else {
document.equation1.setBackgroundColor('#ffffff');
}




(and if(document.equation1.length > 1) also works)

This works beautifully in IE but in firefox it complains about the length method - I assume because when it's not an array, this method doesn't exist.

The exact error is -

Java class webeq3.ViewerControl has no public field or method named "length"


webeq3.ViewerControl is the applets java file which of course has no method called length.
I've also tried a basic isarray function:

function isArray(obj) {
if (obj.constructor.toString().indexOf("Array") == -1)
return false;
else
return true;
}

But IE didn't enjoy that!

Any ideas what I can do?

Thanks

Alex

tallalex85
10-05-2007, 08:35 AM
This is actually a problem with Javascript more than a problem with Java, so could who ever moved it, move it back? It's a problem with checking if an object is an array or not - in Javascript.

Kor
10-05-2007, 09:52 AM
what is equation1? A name? an id? Do you have any other applets on the page?

tallalex85
10-05-2007, 11:42 AM
Yes, it's the name of an applet. To go into a little more detail the page displays 6 equations (through a java applet) which are the possible answers to a quiz it also displays the correct one underneath (which therefore has the same name).