[SOLVED] - Automatically sending values to Iframe

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

[SOLVED] - Automatically sending values to Iframe

Post by anjanesh »

pageA.html

Code: Select all

<html>
<head></head>
<body>
<input type=&quote;button&quote; value=&quote;Click&quote; onclick=&quote;SendValue()&quote; /><br/>
<iframe name=&quote;iframe1&quote; src=&quote;pageB.html&quote;></iframe>
<script type=&quote;text/javascript&quote;>
var result = &quote;test&quote;;
//document.onload = parent.frames&#1111;'iframe1'].Fill(result);
function SendValue()
 {
 	parent.frames&#1111;'iframe1'].Fill(result);
 }
</script>
</body>
</html>
pageB.html

Code: Select all

<html>
<head>
<script type=&quote;text/javascript&quote;>
function Fill(somevalue)
 {
 	alert(somevalue);
 	document.getElementById(&quote;id1&quote;).value = somevalue;
 }
</script>
</head>
<body>
<form id=&quote;frm&quote; action=&quote;test.php&quote; method=&quote;post&quote;>
<input type=&quote;hidden&quote; name=&quote;name1&quote; id=&quote;id1&quote; />
</form>
</body>
</html>
When you click the button the msg box appears with th value from pageA.
But I want this without the click button - automatically. The commented line (Line 8) when uncommented - doesn't seem to work - error:
Error: parent.frames.iframe1.Fill is not a function
Yet it works when you click the button. Anyway to get this work automatically ? It seems the IFRAMe gets loaded only after the parent page gets loaded.

Thanks
Last edited by anjanesh on Thu May 19, 2005 4:19 am, edited 1 time in total.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

so then in your iframe page run a script that grabs the info from the parent.

Code: Select all

document.getElementById('valueOnThisPage')=parent.document.getElementById('somevalue').value;
something like that anyway
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Thanks
Anyway, I got this solved by having a onLoad in the iframe that calls a parent function to do the rest.

pageA

Code: Select all

<script type=&quote;text/javascript&quote;>
function Start()
 {
 parent.frames&#1111;'iframe1'].Fill(result);
 }
..
</script>
<iframe name=&quote;iframe1&quote; src=&quote;pageB.html&quote;></iframe>
pageB

Code: Select all

..
document.onLoad = parent.Start();
..
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

same thing, different way, no worries.
Post Reply