Submitting form from another frame does not run onsubmit of that form

Discussion in 'Javascript' started by Kai Grossjohann, Dec 8, 2003.

  1. I have two frames. Frame "search" contains a search form specifying
    an onsubmit action like so:

    <form ... onsubmit="foo();">
    ...
    </form>

    The other frame contains a <img ... onclick="perform_search();"> where
    the perform_search function is defined as follows:

    <script language="JavaScript">
    function perform_search() {
    var frame = parent.frames.search;
    var form = frame.document.forms.mainForm;
    form.submit();
    }
    </script>

    Now, when hitting Return in the search form, then foo() is called
    fine. But when clicking on the <img ... onclick="perform_search();">
    in the other frame, foo() is NOT called.

    Is expclicitly calling foo() from perform_search() the only way to do
    it, or is there a magic incantation that might do what I want?

    Kai

    PS: I know, what I want is a webapp that also works without
    JavaScript. But sans JavaScript, some pointily-clickety features that
    are absolutely required cannot be implemented, so I need to use
    JavaScript anyway...
     
    Kai Grossjohann, Dec 8, 2003
    #1
    1. Advertising

  2. "Kai Grossjohann" <> wrote in message
    news:...
    <snip>
    >Now, when hitting Return in the search form, then foo() is
    >called fine. But when clicking on the <img ...
    >onclick="perform_search();"> in the other frame, foo() is
    >NOT called.


    Some browsers will call the onsubmit handler for the form when it is
    submitted with the submit method, but the majority won't.

    >Is expclicitly calling foo() from perform_search() the only
    >way to do it,


    It is probably the simplest option.

    >or is there a magic incantation that might do what I want?


    You might try invoking the onsubmit handler as a method of the form
    remotely instead of calling the functions that it would have called
    explicitly:-

    if(form.onsubmit())form.submit();

    -but IE 4 doesn't like that much (though it shouldn't mind).

    There is no such thing as a "magic incantation" in any aspect of
    computer work and thinking like that will only serve to hinder your
    understanding. You are working with machines that perform *only*
    relentless mechanical logic, don't loose sight of that.

    >PS: I know, what I want is a webapp that also works without
    >JavaScript. But sans JavaScript, some pointily-clickety
    >features that are absolutely required cannot be implemented,
    >so I need to use JavaScript anyway...


    So a bad design justifies a worse design?

    Richard.
     
    Richard Cornford, Dec 8, 2003
    #2
    1. Advertising

  3. Kai Grossjohann

    @SM Guest

    Re: Submitting form from another frame does not run onsubmit of thatform

    Kai Grossjohann a ecrit :

    > I have two frames. Frame "search" contains a search form specifying
    > an onsubmit action like so:
    >
    > <form ... onsubmit="foo();">
    > ...
    > </form>
    >
    > The other frame contains a <img ... onclick="perform_search();"> where
    > the perform_search function is defined as follows:
    >
    > <script language="JavaScript">
    > function perform_search() {
    > var frame = parent.frames.search;
    > var form = frame.document.forms.mainForm;


    // ??? quand on peut faire compliqué ...
    parent.search.document.mainForm.submit();
    // va seulement s'interresser à l'Action de mainForm
    // en oubliant complètement le 'onsubmit' y associé
    // à tous z'azzards essayer qque chose comme çà ...
    parent.search.document.mainForm.submit();
    // will only submit the action of search-mainForm
    // forgetting the associated "onsubmit"
    // so try something like that ...

    with(parent.search) {
    if(foo()) document.mainForm.submit();
    else alert('Erore'); }
    }
    </script>


    --
    **************************************************************
    Stéphane MORIAUX : mailto:
    Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
    http://perso.wanadoo.fr/stephane.moriaux/internet/
    **************************************************************
     
    @SM, Dec 8, 2003
    #3
  4. Re: Submitting form from another frame does not run onsubmit of that form

    "@SM" <> wrote in message news:<>...
    > Kai Grossjohann a ecrit :
    >
    > // ??? quand on peut faire compliqué ...
    > parent.search.document.mainForm.submit();
    > // va seulement s'interresser à l'Action de mainForm
    > // en oubliant complètement le 'onsubmit' y associé
    > // à tous z'azzards essayer qque chose comme çà ...
    > parent.search.document.mainForm.submit();


    Excuse moi, je ne comprend pas de Français. Je voudrais usez Anglais.
    D'accord?

    I hope I understood that right: the temp variable is useless because
    it is used only once.

    Of course, you're right. The code stems from some debugging -- I had
    an alert statement between the two original statements.

    > // will only submit the action of search-mainForm
    > // forgetting the associated "onsubmit"
    > // so try something like that ...
    >
    > with(parent.search) {
    > if(foo()) document.mainForm.submit();
    > else alert('Erore'); }
    > }
    > </script>


    Ah, that would work? Cool!

    Kai
     
    Kai Grossjohann, Dec 9, 2003
    #4
  5. Kai Grossjohann

    @SM Guest

    Re: Submitting form from another frame does not run onsubmit of thatform

    Kai Grossjohann a ecrit :

    > "@SM" <> wrote in message news:<>...
    > > Kai Grossjohann a ecrit :
    > >
    > > // ??? quand on peut faire compliqué ...

    >
    > Excuse moi, je ne comprend pas de Français. Je voudrais usez Anglais.
    > D'accord?


    Escuse me, I though having read a word in french sommewhere in the script ...
    And I'm not too strong in English ;-)

    I replace your code by

    > > parent.search.document.mainForm.submit();


    Of course this new code would no more work with the foo() on submit
    because (I think so) :

    > // it will only submit the action of search-mainForm
    > // forgetting the associated "onsubmit"


    > I hope I understood that right: the temp variable is useless because
    > it is used only once.


    ??? why to divise a simple call in sticks ?
    parent.search.document.mainForm. is the path to find the right submit()
    This code is used at each time you call the function
    It would have to be replaced with :

    > > with(parent.search) {


    // using the frame 'search' containt in parent window

    > > if(foo()) document.mainForm.submit();


    /*
    if function foo() (of document opened in 'search')
    (I think that functions declared in a document belong to their own window)
    that means :
    - the foo() must run. All as 'onsubmit' in normal way
    - before answering 'true' or 'false'
    - then ==>
    - if 'true' is returnd
    submit the form 'mainForm' of document (in 'search')
    */

    > > else alert('Erore'); }

    >
    > Ah, that would work?


    I didn't try it myself, it is only an idea ...
    Of course foo() after its own running must return false or true
    just as it would do if used in 'onsubmit'

    could be :
    if(parent.search.foo()) parent.search.document.mainForm.submit();

    or
    temp=parent.search;
    // parent.frames['searh']
    // parent.frames[0]
    if(temp.foo()) temp.document.mainForm.submit();
    // temp.document.forms[0].submit()

    Try to use : window.frames[0].document.forms[0]
    instead of : window.nameOfFrame.document.nameOfForm
    to be more compatible with DOM

    > Cool!


    Perhaps ... I hope so .... :)

    --
    **************************************************************
    Stéphane MORIAUX
     
    @SM, Dec 9, 2003
    #5
    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. Kathryn
    Replies:
    4
    Views:
    338
  2. J Kester
    Replies:
    0
    Views:
    288
    J Kester
    Dec 23, 2003
  3. threeflush

    submitting a form through another frame

    threeflush, Feb 7, 2005, in forum: Javascript
    Replies:
    10
    Views:
    213
    Archimedes Trajano
    Aug 29, 2005
  4. Danny & Noemi Shafir

    Prevent submitting from another frame

    Danny & Noemi Shafir, Jul 19, 2005, in forum: Javascript
    Replies:
    0
    Views:
    116
    Danny & Noemi Shafir
    Jul 19, 2005
  5. Simon
    Replies:
    1
    Views:
    107
    Simon
    Jul 17, 2007
Loading...

Share This Page