By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,501 Members | 1,660 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,501 IT Pros & Developers. It's quick & easy.

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

P: n/a
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));
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
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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));
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 <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_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-deve...upgrade_2.html
Jul 23 '05 #2

P: n/a
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
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.