Olaf wrote:
I have a frameset page witch contains the myFuc() function. The
function is accessed from a page in one of the frames in the frameset.
An example is shown below.
<input onclick="javascript:alert('document.forms(0)='+doc ument.forms(0));
[1]^^^^^^^^^^^ [2]^^^^^^^^^^^^^^^^
[1] Remove that, see the FAQ: <http://jibbering.com/faq/>
[2] document.forms as of the still proprietary, yet widespread, DOM
Level 0 (IE/NN 3+) is a collection, a special object, not a method
(it is now defined as Document.forms HTMLCollection object in the
W3C DOM as well, however `document' is apparently still
proprietary). Use the square bracked property accessor of
ECMAScript, in called the "index operator" in J(ava)Script:
document.forms[0]
BTW: Has it ever occurred to you that client-side scripting
may be disabled and thus the button will do nothing then?
parent.myFunc(document.forms(0));" type="button" value="Open"
name="Button" ID="Button">
The strange part is that the debug alert says that the
document.forms(0) is an object så all seem to be well. But directly
afterwords when parent.myFunc(document.forms(0)) is to execute, the
page halts with the "Object doesn't support this property or method"
error message.
How can it be allright first and then not?
All I can say for sure is that strange syntax often causes strange
behaviour. In your case, document.forms(0) is first used as substring
in a concatenation operation, which would require its value to be
converted to a string prior, using the toString() method on it
internally. However, using the same term as argument for your
function causes it to be evaluated as an object reference. A proper
DOM and script engine would have yield an error like "document.forms
is not a method" in both cases as the call operator (the parantheses)
was used for a non-function property. However, the IE DOM is known
to allow this ambiguity for its host objects: elements of some,
possibly all, collections can be accessed both via the call and the
index operator, the collections being apparently both function and
non-function properties. And the error message you have reported
suggests that you are testing with IE (which you should have reported, too).
PointedEars