View Full Version : frames
chrismiceli
09-25-2002, 11:31 PM
I have a page going to get a variable from another frame, but it says parent.frames[1].document.stats.speed.value is null or not an object, here is a snipet of code
<html>
<head>
<title>test</title>
</head>
<body>
<script language="javascript">
var fspd = parent.frame[1].document.stats.speed.value
// stats is the name of the form with input type="hidden" values"
// yes it is the second fram I want the info from, not frame[0]
</script>
</body>
</html>
It says that that is null or not an object, here is was the other frame looks like
<html>
<head>
<title>test</title>
</head>
<body>
<form name="stats">
<input type="hidden" name="speed" value="4">
</form>
</body>
</html>
joh6nn
09-26-2002, 12:32 AM
parent.frame[1]
try parent.frames[1]
chrismiceli
09-26-2002, 06:45 AM
still isn't working
adios
09-26-2002, 07:00 AM
You're running the code in top-level script (outside of a function) so it's presumably trying to retrieve the value before it exists. You'll need to use the onload handler of the <frameset> document:
http://www.faqts.com/knowledge_base/view.phtml/aid/1703/fid/127
Just guessing here since the order of events in unclear...
chrismiceli
09-26-2002, 07:26 AM
I am trying to declare variables so they can be used by all my frames, I figured out that if I declare varibles with the parent.frame1.... it can work but only in a function. When I try the following script no frames can use those variables, is there a way where I could declare variables outside of functions that could used by all frames. the variables by the way are in one of the frames!
<html>
<head>
<title>test</title>
<script language="javascript">
there() {
spd = parent.frame2.document.form1.trial0.value;
att = parent.frame2.document.form1.trial.value;
</script>
</head>
<frameset cols="89%, *" onLoad="there()">
<frame src="test0.html" name="frame1">
<frame src="stats.html" name="frame2">
</frameset>
adios
09-26-2002, 07:34 AM
Any time you assign a variable without declaring it first (no var keyword) - even inside a function - it's implicitly declared as a global, and should be visible to scripts running in other frames. Remember - since the above script is running in the top window (frameset doc) you access it from elsewhere as:
top.spd
top.att
(don't forget the 'function' keyword)
chrismiceli
09-26-2002, 06:05 PM
nm, I think I got it, thanx for the help.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.