PDA

View Full Version : print outside the iframe?



d-machine
07-16-2008, 08:04 PM
Hi

I have a simple iframe inside a table. This iframe includes a php form, that after sending it, should print a simple message outside the iframe (in the page, I don't care where..)

Can JavaScript help me to print it outside the iframe?

jscheuer1
07-17-2008, 01:21 AM
Don't you mean when submitting the form? And you don't really mean print, except from the programming point of view, right? If I've got that right - say this is the beginning of your form in your iframe:


<form action="whatever" method="whatever"
onsubmit="top.document.getElementById('form_response').firstChild.nodeValue =
'Some simple message';return true;">

And on your top page you have:


<div id="form_response">&nbsp;</div>

it should all work out.

jscheuer1
07-17-2008, 01:53 AM
I just tested this out to be sure and it works fine, except in FF if you refresh the top page and submit again there is an error. This can be avoided by a short script on the top page that refreshes the iframe to its original source on reload of the top page. Here are my two pages, added code highlighted -

top page:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
window.onload = function(){
document.getElementById('form_frame').src = 'form.htm';
}
</script>
</head>
<body>
<iframe id="form_frame" src="form.htm" width="300" height="300" scrolling="auto" frameborder="1"></iframe>
<div id="form_response">&nbsp;</div>
</body>
</html>


form.htm:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>
<body>
<form action="#"
onsubmit="top.document.getElementById('form_response').firstChild.nodeValue =
'Some simple message';return true;">
<input type="submit" value="Go">
</form>
</body>
</html>

d-machine
07-17-2008, 06:50 AM
Thank you very much !!!!!