strange "Object doesn't support this property or method" problem

O

Olaf

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)='+document.forms(0));
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?

/Olaf
 
G

Grant Wagner

Olaf said:
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)='+document.forms(0));
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?

/Olaf

Are you sure it isn't parent that doesn't support myFunc().

Try alert(parent.myFunc);

Also, the proper notation for collections in Javascript is using square
brackets. Curved brackets (braces) may work in Internet Explorer, but it will
break in any other browser. So use document.forms[0] rather then
document.forms(0)

And you don't need the "javascript:" label in events unless you've defined
your first script block as <script language="VBScript">.

And you don't need to refer to the form using the complete DOM hierarchy if
it's the same form the current element resides in, because each form element
has a property "form" which refers to it's parent form.

So putting it all together...

<input onclick="alert(parent.myFunc); /* parent.myFunc(this.form); */"
type="button" value="Open" name="Button" ID="Button">

--
| Grant Wagner <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html
 
T

Thomas 'PointedEars' Lahn

Olaf said:
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)='+document.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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top