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 SkipVought 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 the form elements within an IFrame

Status
Not open for further replies.
Feb 9, 2007
46
0
0
US
Hi,

I have a page with 2 IFrames and a single submit button at the main page:

IFrame.asp

Code:
<html>

<head>
<title>IFrame</title>
</head>

<body>
<form action="formresults.asp">
<iframe name="iFrame1" id="iFrame1" src="iframe1.html">

</iframe>

<iframe name="iFrame2" id="iFrame2" src="iframe2.html">

</iframe>
<br>
<input type="submit" value="Submit">
</form>
</body>

</html>

iFrame1.html

Code:
<html>

<head>
<title>IFrame1</title>
</head>

<body>

Text1: <input type="Text" name="txtIFrame1" value="Text in iFrame1">

</body>

</html>

iframe2.html

Code:
<html>

<head>
<title>IFrame2</title>
</head>

<body>

Text2: <input type="Text" name="txtIFrame2" value="Text in iFrame2">

</body>

</html>

In the target page - formresults.asp, I have a simple script to grab all form elements

Code:
<%
for x = 1 to Request.Form.count()
        Response.Write(Request.Form.key(x) & " - ")  'will return the form field name
        Response.Write(Request.Form.item(x) & "<br>")  'will return the value
    next
%>

But this page displays nothing. How can I display the name of the form elements within the IFrames?

Thanks.
 
Hi,
you can't access the objects in thoes two iframes from the formresults.asp file becuase actually nothing have been posed to that file.
the solution is that before submitimg the IFrame.asp page you have to call a javascript function to read the data from the objects inside those two ifranes and load them in the hidden objects in your form, then submit the form.
here is a sample of the idea...
note that I've made some changes in your code :

IFrame.asp
Code:
<html>

<head>
<title>IFrame</title>
[b]
<script language="javascript">
function loadData(){
	document.IFrameForm.txtIFrame1.value = document.frames("iFrame1").document.getElementById('txtIFrame1').value;
	document.IFrameForm.txtIFrame2.value = document.frames("iFrame2").document.getElementById('txtIFrame2').value;
}
</script>
[/b]
</head>

<body>
<form name="IFrameForm" action="formresults.asp" [b]method="post" onsubmit="javascript:loadData();"[/b]>
[b]<input type="hidden" name="txtIFrame1">
<input type="hidden" name="txtIFrame2">[/b]
<iframe name="iFrame1" id="iFrame1" src="iframe1.html">

</iframe>

<iframe name="iFrame2" id="iFrame2" src="iframe2.html">

</iframe>
<br>
<input type="submit" value="Submit">
</form>
</body>

</html>

iFrame1.html
Code:
<html>

<head>
<title>IFrame1</title>
</head>

<body>

Text1: <input type="Text" name="txtIFrame1" [b]id="txtIFrame1"[/b] value="Text in iFrame1">

</body>

</html>

iframe2.html
Code:
<html>

<head>
<title>IFrame2</title>
</head>

<body>

Text2: <input type="Text" name="txtIFrame2" [b]id="txtIFrame2"[/b] value="Text in iFrame2">

</body>

</html>

and there's no change in the file formresults.asp

I hope this clue could help you solve your problem...

----
Harsh words break no bones but they do break hearts.
E.T.
 
This was just one control. If there are many HTML elements within the control, form would end up having a lot of hidden elements.

Thanks for the input.
 
Hi,
yes, but as long as there's no other way, it's your only solution.
now, on choice which you have is that you don't create the hidden elements your self and in that javascript you can loop between elements in those two IFrames and generate them on the fly in the main IFrame.asp file.
and remember that those hidden objects don't increase the size of the posted data, because the elements in those two iframes are not posting anyway...

Have fun...

----
Harsh words break no bones but they do break hearts.
E.T.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top