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

Discussion in 'Javascript' started by Olaf, Jun 14, 2004.

  1. Olaf

    Olaf Guest

    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
     
    Olaf, Jun 14, 2004
    #1
    1. Advertising

  2. Olaf

    Grant Wagner Guest

    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)='+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 <>

    * 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
     
    Grant Wagner, Jun 14, 2004
    #2
    1. Advertising

  3. 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)='+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
     
    Thomas 'PointedEars' Lahn, Jun 25, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. todd
    Replies:
    3
    Views:
    5,859
  2. Roman
    Replies:
    0
    Views:
    4,055
    Roman
    Jan 4, 2004
  3. zdrakec
    Replies:
    0
    Views:
    599
    zdrakec
    Sep 26, 2007
  4. Joe
    Replies:
    3
    Views:
    565
  5. JohnE
    Replies:
    1
    Views:
    1,068
    JohnE
    Mar 9, 2010
Loading...

Share This Page