posting content to an iframe

M

mike

I have a page with a form as follows:

<form name="updfrm" method="post" action="update_db.cfm">
<input type="text" name="myfield" value="stuff">
<button onclick="sub_this();">press here</button>
</form>

normally I would either 1) let this form post to this window, or 2)
open a window and post to it.

I'd like to try posting that using an iframe.

So, I create that iframe in the same page as the form like:

<div style="display:none">
<iframe src="" id="update_iframe" name="update_iframe">
</iframe>
</div>

The script that takes the content from the form and updates the
database is called update_db.cfm.

So, my function looks like:

function sub_this()
{
var mycgi = "update_db.cfm";
document.getElementById('update_iframe').src=mycgi;
document.updfrm.target = document.frames['update_iframe'];
document.updfrm.submit();
}

My browser IE6 does not like this at all. Its dieing and barfing.

Anyone see any problems here.

I have gotten this to work using get, but not post. Using get my
sub_this function would look like:

function sub_this()
{
var mycgi = "update_db.cfm?thecontent=" +
document.updfrm.elements['myfield'].value;
document.getElementById('update_iframe').src=mycgi;
}

I don't really want to use get because I'd have to encode every
variable in the url. Some of them may be long.

Mike
 
W

web.dev

mike said:
I have a page with a form as follows:

<form name="updfrm" method="post" action="update_db.cfm">
<input type="text" name="myfield" value="stuff">
<button onclick="sub_this();">press here</button>
</form>

normally I would either 1) let this form post to this window, or 2)
open a window and post to it.

I'd like to try posting that using an iframe.

So, I create that iframe in the same page as the form like:

<div style="display:none">
<iframe src="" id="update_iframe" name="update_iframe">
</iframe>
</div>

The script that takes the content from the form and updates the
database is called update_db.cfm.

So, my function looks like:

function sub_this()
{
var mycgi = "update_db.cfm";
document.getElementById('update_iframe').src=mycgi;
document.updfrm.target = document.frames['update_iframe'];
document.updfrm.submit();
}

If the page with your form is already in the iframe, there is no need
to do a target. Just let the form submit and let it post back to the
same page.
 

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

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,197
Latest member
Sean29G025

Latest Threads

Top