nikon70
asked on
iframes: passing a value from a parent to its child iframe
I am trying to pass a value from pageone.htm which is the parent to its child iframe pagetwo.htm
sequence:
once the iframe page had loaded
i have a hidden textfield which is holding the value to be entered into the child frame form
once entered into the child frame to submit the form in the child frame
but i can not seem to get anything working.
Thanks for your help ...
sequence:
once the iframe page had loaded
i have a hidden textfield which is holding the value to be entered into the child frame form
once entered into the child frame to submit the form in the child frame
but i can not seem to get anything working.
Thanks for your help ...
A frame value can be accesed by
window.frameName.document. getElement ById('elem entId1').v alue
or
window.frames[0].document. getElement ById('elem entId1').v alue
This link is useful in understanding the relation ship between child frame and parent frame.
http://www.yourhtmlsource.com/javascript/scriptingframes.html
http://www.java2s.com/Tutorial/JavaScript/0420__HTML-Tags/Referencetheparentframe.htm
http://www.webmasterworld.com/forum91/5212.htm
window.frameName.document.
or
window.frames[0].document.
This link is useful in understanding the relation ship between child frame and parent frame.
http://www.yourhtmlsource.com/javascript/scriptingframes.html
http://www.java2s.com/Tutorial/JavaScript/0420__HTML-Tags/Referencetheparentframe.htm
http://www.webmasterworld.com/forum91/5212.htm
Use the code below:
The changes are:
* transferFields() is called to move the contents of the hidden form to the iframe field
* named the iframe 'frame1'
* named the form in the iframe file 'frmFood'
* named the field in the iframe form 'favfood'
The changes are:
* transferFields() is called to move the contents of the hidden form to the iframe field
* named the iframe 'frame1'
* named the form in the iframe file 'frmFood'
* named the field in the iframe form 'favfood'
pageone.htm
<html><head><title>test</title>
<script LANGUAGE="JavaScript">
function transferField() {
dat=document.TheForm.name.value;
window.frame1.frmFood.favfood.value=dat;
}
window.onload=transferField;
</script>
</head>
<form name="TheForm">
<input type=hidden name="name" value="cooking">
</form>
Form is hidden
<p>
<iframe name="frame1" style="width: 500px; height: 300px;" src="/iframe/pagetwo.htm"></iframe>
</body>
</html>
pagetwo.htm
<FORM name="frmFood" action="http://mysite.com/" method="post">
<P>
<LABEL for="favfood">fav food: </LABEL>
<INPUT type="text" id="favfood" name="favfood"><BR>
<INPUT type="submit" value="Send"> <INPUT type="reset">
</P>
</FORM>
ASKER
for some reason this does not work in firefox but works in IE ... any reason why ?
ASKER
i have made a few tweeks to this to encorporate it into my site. and now even in IE it will not enter the data into the iframe text field.
pageone.php
<html><head><title>test</title>
<script LANGUAGE="JavaScript">
function transferField(data) {
dat=data;
window.frame1.frmFood.favfood.value=dat;
}
</script>
</head>
<body>
<form name="TheForm">
<input type=hidden name="name" value="cooking">
</form>
<p>
<iframe name="frame1" style="width: 500px; height: 300px;" src="/iframe/pagetwo.htm"></iframe>
<?
$filename = "/home/content/t/o/m/tomjoffe/html/iframe/file.txt";
$fd = fopen ($filename, "r");
$contents = fread ($fd,filesize ($filename));
fclose ($fd);
$delimiter = ";";
$splitcontents = explode($delimiter, $contents);
$data = $splitcontents[0];
unset($splitcontents[0]);
$newcontents = implode($delimiter,$splitcontents);
$fd = fopen ($filename, "w+");
fwrite($fd, $newcontents);
fclose ($fd);
print "<script>transferField('$data');</script>";
?>
</body>
</html>
pagetwo.htm
<FORM name="frmFood" action="http://mysite.com/" method="post">
<P>
<LABEL for="favfood">fav food: </LABEL>
<INPUT type="text" id="favfood" name="favfood"><BR>
<INPUT type="submit" value="Send"> <INPUT type="reset">
</P>
</FORM>
Just being firefox? :-)
Change the transferField() function to:
function transferField() {
dat=document.TheForm.name. value;
document.getElementById('f rame1').co ntentWindo w.document .frmFood.f avfood.val ue=dat;
}
and give the iframe also an id, like:
<iframe id="frame1" name="frame1" style="width: 500px; height: 300px;" src="iframe.htm"></iframe>
This should work in IE and FF.
Change the transferField() function to:
function transferField() {
dat=document.TheForm.name.
document.getElementById('f
}
and give the iframe also an id, like:
<iframe id="frame1" name="frame1" style="width: 500px; height: 300px;" src="iframe.htm"></iframe>
This should work in IE and FF.
ASKER
this throws error in IE favfood is null or not an object
still not working in FF :(
can you take a look at my recent code paste as this is how it is working now.
still not working in FF :(
can you take a look at my recent code paste as this is how it is working now.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thats great got it to work, how do i auto submit after i have entered the data?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
perfect!! thanks!!
do you know anything about cross domain library calls?
do you know anything about cross domain library calls?
Not that much. And probably better if you make a new question for it, in the right sections, so the
right (who know more! :) ) people can respond too.
right (who know more! :) ) people can respond too.
ASKER
Open in new window