[SOLVED] Pass content from Frame to another

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] Pass content from Frame to another

Post by anjanesh »

Let say a page has has 2 frames :
page0.htm

Code: Select all

<frameset cols="50%,*">
  <frame name="left" src="page1.htm">
  <frame name="right" src="page2.htm">
</frameset>
page1 has a textbox and a submit button.
When I hit the submit button is it possible to display value of textbox in page2 ?
I tried have a 'global' function in page0 where I did var v=document.getElementById("text1").value and set a page2's variable with this v. But this is not working ?
Possible ? If not any other way ?
Thanks
Last edited by anjanesh on Tue Dec 27, 2005 4:38 am, edited 2 times in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I believe..

Code: Select all

top.frames&#1111;'right'].getElementById('text1').value = 'whatever';
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Thanks.
For searching :
Also works : - [Edit] DOES NOT WORK

Code: Select all

parent.frames['right'].getElementById('text1').value = 'whatever';
parent.frames[2].getElementById('text1').value = 'whatever';
Last edited by anjanesh on Tue Dec 27, 2005 4:42 am, edited 1 time in total.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Errata: (For those who end up here by searching)

Code: Select all

parent.frames['right'].getElementById('text1').value = 'whatever';
In order to change value of input type in another frame, parent.frames[framename].getElementById() cannot be used.
Instead a userdefined function in framename that updates the value must be called.
Frame 0: name : left

Code: Select all

.
<script type="text/javascript">
parent.frames['right'].UpdateText1('whatever');
</script>
.
Frame 1: name : right

Code: Select all

.
<script type="text/javascript">
function UpdateText1(NewValue)
 {
 	document.getElementById("text1").value = NewValue;
 }
</script>
.
<input type="text"; id="text1">
.
Post Reply