Click to See Complete Forum and Search --> : Undefined error when passing variable between child frames
jjohnstn
03-07-2003, 01:27 PM
I keep getting an error when attempting to pass a variable from one child frame (contentframe) to another (topframe)
from contentframe:
<SCRIPT>
top.topframe.document.somevar.value = "testing123"
</SCRIPT>
and then in the body of topframe:
<SCRIPT> document.write(somevar); </SCRIPT>
Both child frames reside in the same frameset, so I suppose using "parent" instead of top should also work, but neither do.
The method needs to work in as many browsers as possible, including AOL. I tried writing to a DIV tag, while it works it isn't supported by older browsers.
khalidali63
03-07-2003, 02:23 PM
The way you have posted your code,it seems to me that the upper frame has no idea that "samevar" is a variable,let alone it has been changed in the another frame,a simple way of doing this is change the varaible or print it from the frame where variable changes.
Khalid
Dan Drillich
03-07-2003, 03:34 PM
Please try -
index.html
<HTML>
<FRAMESET ROWS="20%,80%">
<frame src="topframe.html" name="topw">
<frame src="contentframe.html" name="bottom">
</FRAMESET>
</HTML>
topframe.html
<form name="f">
<input type="text" name="somevar">
</form>
contentframe.html
<SCRIPT>
// either one
parent.topw.document.f.somevar.value = "testing123";
top.topw.document.f.somevar.value = "testing124";
</SCRIPT>
jjohnstn
03-07-2003, 04:26 PM
That works, but does not solve the problem of
<SCRIPT> document.write(somevar); </SCRIPT>
not working.
I need to take the variable in the top frame as change font, etc. A text box won't work.
jjohnstn
03-07-2003, 04:28 PM
Originally posted by khalidali63
The way you have posted your code,it seems to me that the upper frame has no idea that "samevar" is a variable,let alone it has been changed in the another frame,a simple way of doing this is change the varaible or print it from the frame where variable changes.
Khalid
I had tried writing the variable to the same frame in which it was set, to make sure it was indeed being set. While it would display there, it would not display in the topframe.
khalidali63
03-07-2003, 04:31 PM
Ohhkkay..well could you put all of the code in a zip file an upload it here so that some one can make it work for you?
Cheers
Khalid
Taken from Dan's script:
index.html
code:--------------------------------------------------------------------------------
<HTML>
<FRAMESET ROWS="20%,80%">
<frame src="topframe.html" name="topw">
<frame src="contentframe.html" name="bottom">
</FRAMESET>
</HTML>
--------------------------------------------------------------------------------
topframe.html
code:--------------------------------------------------------------------------------
<div id="somevar"></div>
--------------------------------------------------------------------------------
contentframe.html
code:--------------------------------------------------------------------------------
<SCRIPT>
// either one
parent.topw.somevar.innerHTML = "testing123";
top.topw.somevar.innerHTML = "testing124";
</SCRIPT>
jjohnstn
03-07-2003, 04:36 PM
Originally posted by khalidali63
Ohhkkay..well could you put all of the code in a zip file an upload it here so that some one can make it work for you?
Cheers
Khalid
Zip file is attached, thanks very much!
jjohnstn
03-07-2003, 04:41 PM
[QUOTE]Originally posted by Jona
[B]Taken from Dan's script:
<div id="somevar"></div>
-------------------------------
top.topw.somevar.innerHTML = "testing124";
Thank you that works, but older browsers do not support it unfortunately.
Yah, that's true... How 'bout this instead:
<body>
blah blah blah, tables add whatever here
<script>var somevar = ""; document.write(somevar)</script>
</body>
jjohnstn
03-07-2003, 06:19 PM
Originally posted by Jona
Yah, that's true... How 'bout this instead:
<body>
blah blah blah, tables add whatever here
<script>var somevar = ""; document.write(somevar)</script>
</body>
Maybe I'm missing something, but how would resetting the variable to empty right before printing be of any use? The variable was set in another frame to a value, which is not being carried over to this topframe.
Never mind what I said. I'm stupid...