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

  • Thread starter Kai Grossjohann
  • Start date
K

Kai Grossjohann

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...
 
R

Richard Cornford

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.
 
@

@SM

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:[email protected]
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
http://perso.wanadoo.fr/stephane.moriaux/internet/
**************************************************************
 
K

Kai Grossjohann

@SM said:
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
 
@

@SM

Kai Grossjohann a ecrit :
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

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 :

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

/*
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')
*/
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

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

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top