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

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

P: n/a
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...
Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Kai Grossjohann" <Ka*************@gmx.net> wrote in message
news:e8**************************@posting.google.c om...
<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.
Jul 20 '05 #2

P: n/a
@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:st*********************@wanadoo.fr
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
http://perso.wanadoo.fr/stephane.moriaux/internet/
************************************************** ************
Jul 20 '05 #3

P: n/a
"@SM" <st**************@wanadoo.fr> wrote in message news:<3F***************@wanadoo.fr>...
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
Jul 20 '05 #4

P: n/a
@SM
Kai Grossjohann a ecrit :
"@SM" <st**************@wanadoo.fr> wrote in message news:<3F***************@wanadoo.fr>...
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

Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.