Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to submit a form in Frame B with a button in Frame A using FireFox

Status
Not open for further replies.

FvS

Programmer
Apr 5, 2006
20
NL
Hi all,

I have to frames:
And in FrameA i have the following link:

function submitform() {
if ( parent.frames.service.document.bodyinvoer.onsubmit())
{
parent.frames.service.document.bodyinvoer.submit();
}
}
<a href="javascript:submitform()">Submit</a>

This link works perfectly in IE it first runs het onsubmit handler and checks the forms and if it's ok it submit's the form, but in Firefox nothing happens[/color red] What am i doing wrong?
 
Hmm - although why you are checking the existence of an onsubmit handler, I don't know. Surely you should be checking for the return value of your onsubmit handler, rather than for its presence?

Unless, of course, your onsubmit handler is actually called "onsubmit" - in this case, I would strongly suggest you rename it, and then put the brackets back.

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hi Dan,

When i use youre example:
if (parent.frames['service'].document.forms['bodyinvoer'].onsubmit)

Then it doesn't work in IE and FireFox but when i put the brackets back it only works in IE.

Youre are suggesting that the function only checks if there exists an onsubmit handler, but i thought that:
if (parent.frames['service'].document.forms['bodyinvoer'].onsubmit()) executes the onsubmit-handler and the if statement evaluates the outcome. because in IE it checks the form i'am trying to submit and holds on errors etc...

Do you know if there is a guideline for making webpages for FireFox?
 
What is your onsubmit handler called? What do you have in the "onsubmit" attribute of your form tag?

If you have:

Code:
<form ... onsubmit="onsubmit();" ...>

then you should rename your function from "onsubmit" to something else.

If you have something else already:

Code:
<form ... onsubmit="myOnSubmitFunc();" ...>

then you should use that name in your "if" test - with brackets after it.

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
My code is like this

Code:
<form ... onsubmit="myOnSubmitFunc();" ...>
 
When i follow youre advice then it doesn't work in either IE or FireFox, maybe i am doing het wrong could you please specify an example of what you mean?

I have the following:
Frame A contains:
Code:
<html>
<head>
<script language="javascript">
<!--
function submitform() {
 if ( parent.frames['service'].document.forms['bodyinvoer'].onsubmit() )
    {
      parent.frames['service'].document.forms['bodyinvoer'].submit();
     }
}
-->
</script>
</head>
<body>
<a href="javascript:submitform()">Submit</a>
</body>
</html>

Frame B contains:
Code:
<html>
<head></head>
<body>
<script language="JavaScript">
  function formcontrole() 
   { return true }
</script>
<form name="bodyinvoer" method="post" onSubmit="return formcontrole()">
</form>
</body>
</html>

This construction works fine in IE but does nothing in FireFox.
 
You don't need to test anything - simply submit the form:

Code:
parent.frames['service'].document.forms['bodyinvoer'].submit();

The validation function should do the rest (assuming you've written it to return false if validation fails, true otherwise).

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hi Dan,

Now it does submit the form, but the onsubmit event isn't triggered so an incomplete form is being submitted.
 
[1] case sensitivity
>[tt]<form name="bodyinvoer" method="post" onSubmit="return formcontrole()">[/tt]
[tt]<form name="bodyinvoer" method="post" on[highlight]s[/highlight]ubmit="return formcontrole()">[/tt]
[2][tt]
function submitform() {
if ( parent.frames['service'].document.forms['bodyinvoer'].onsubmit[highlight] [/highlight] )
{
[blue]var b=parent.frames['service'].document.forms['bodyinvoer'].onsubmit();[/blue]
[blue] if (b) {[/blue]
parent.frames['service'].document.forms['bodyinvoer'].submit();
[blue]}[/blue]
}
}
[/tt]
 
Aaah - sorry yes.. my mistake.

OK - Try following my advice from 2 posts back, which you still have not done:

Code:
if (parent.frames['service'].document.forms['bodyinvoer'].[!]formcontrole()[/!])

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
In general, form does not necessarily have a onsubmit handler attached to it, the if() testing the existnece of one, then proceed forward. If the form does not have one, the routine is meant not to do anything. You sure can instruct what to do if there is not an onsubmit handler attached to the form by beefing up the function submitform. This is the full meaning and significance of this construction.
 
Hi Dan and tsuji,

Both youre suggestions don't work:
Dan youre suggestion i've already tryed that.

Tsuji, youre suggestion only works in IE, FireFox doesn't respond
 
Dan, no it doesn't work in either browser.

tsuji, if have corrected both cases.

i keep finding it strange that it works in IE but Firefox doesn't seems to react at al.
 
If the onsubmit handler is correctly scripted with return true/false, it will do as said. I've tested it with a demo working for ie and moz and that I have not much doubt about it. Hope both pages are from the same domain.
 
tsuji,

Could you share youre demo here?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top