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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Olaf

    #1

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

    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="javaSc ript:alert('doc ument.forms(0)= '+document.form s(0));
    parent.myFunc(d ocument.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(d ocument.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
  • Grant Wagner

    #2
    Re: strange &quot;Object doesn't support this property or method&quot; problem

    Olaf wrote:
    [color=blue]
    > 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="javaSc ript:alert('doc ument.forms(0)= '+document.form s(0));
    > parent.myFunc(d ocument.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(d ocument.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[/color]

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

    Try alert(parent.my Func);

    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="VBScr ipt">.

    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(t his.form); */"
    type="button" value="Open" name="Button" ID="Button">

    --
    | Grant Wagner <gwagner@agrico reunited.com>

    * Client-side Javascript and Netscape 4 DOM Reference available at:
    *


    * 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


    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: strange &quot;Object doesn't support this property or method&quot; problem

      Olaf wrote:[color=blue]
      > 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="javaSc ript:alert('doc ument.forms(0)= '+document.form s(0));[/color]
      [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?
      [color=blue]
      > parent.myFunc(d ocument.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(d ocument.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?[/color]

      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.f orms
      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

      Comment

      Working...