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 TouchToneTommy 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, after another form (within iframe) is submitted?

Status
Not open for further replies.

arnwald

Programmer
Jun 11, 2001
8
VE
Hi,
Let "pageP" be a page which contains a form "formP" and an inline frame (iframe tag) with another page. Let "pageC" be the latter page. Now, when the user submits a form within "pageC" (the one inside the iframe), I need to submit automatically "formP" after "formC" has been submitted.
This is because "pageP" has to reflect changes made by submitting "formC" in "pageC", once "pageP" has been reloaded. Pages are dynamically generated by servlets.
I need support for IE5+, NS6, and standard-compliant browsers.

Any ideas will be appreciated.
 
Hi!
I’m not shure that u’re lookin for this, but here is the code 2 change parent’s form from iframe (or frame):
In the ‘parent’ file:

<script>
function getSel(obj){
var temp
for (var ii=0; ii<obj.length; ii++ ) if (obj[ii].selected) temp=obj[ii].text
if (temp) return temp
else return false
}

function getFromiframe(){
var ow=frames.dedada.document.forms.daForm.Sel.options
document.forms.myform.needed.value=getSel(ow)
}
</script>



<form id='myform' name='myform' method=&quot;post&quot; action=&quot;&quot;>
<input type=textbox id='needed' name='needed' ><br>
</form>
<iframe name=dedada id=dedada src='file1.htm'></iframe>


in the file1.htm:


<form name=&quot;daForm&quot; >
select field:<select name=&quot;Sel&quot; >
<option> aaa
<option> bbb
</select>
<input type=button value='letsrock' onclick='top.getFromiframe()'>
</form>

 
Hi vituz, thanks for your tip.

So far, I think a good start is to set a couple of events in order to trigger the functions.
When submitting a form, onsubmit is triggered (by the form itself) and then, after around 1 sec, onunload is triggered (by the window). So I thought that it would be an appropriate strategy, to use

Code:
onunload=&quot;top.document.formP.submit()&quot;

but I tested this on IE5 and it appears to ignore this code, since it does not produce any error, but formP is not submitted. I read on another thread (here at tek-tips.com) that IE5 appears to ignore the statement to submit a form on certain occasions. So i tried onbeforeunload and it appears to work Ok, but this is a proprietary feature of IE (and hence, not supported by NS6).

I'm testing the next code now, but appears to work only a few times (I'm not sure whether this has anything to do with the browser cache ..??):
On the parent window (pageP), no code is placed. Everything will be done from the child window within an iframe tag (pageC).
Code:
<script type=&quot;text/javascript&quot;>
function submitTop() {
  var frmObj = top.document.getElementById('formP');
  frmObj.submit();
}
</script>
...
<form id=&quot;formC&quot; action=&quot;...&quot; method=&quot;post&quot; onsubmit=&quot;setTimeout('submitTop();',10)&quot;>
The idea behind using setTimeout is to execute submitTop() after onsubmit is triggered, but before onunload occurs, trying to simulate the onbeforeunload handler.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top