...

View Full Version : Passing variables from one frame to another



romram
04-26-2004, 11:10 PM
I have write code to use variable from another frame, but the code didn't work?


<script>
var wronganswer1,wronganswer2,
fiftyfiftyUsed="notUsed";
function fiftyfifty()
{
if(fiftyfiftyUsed=="notUsed"){
wronganswer1 = Math.round(Math.random() * 2 + 2);
wronganswer2 = Math.round(Math.random() * 2 + 2);
while (wronganswer2 == wronganswer1) {wronganswer2 = Math.round(Math.random() * 2 + 2);};
if((parent.frames("question").document.answer1==wronganswer1)||(parent.frames("question").document.answer1==wronganswer2))
parent.frames("question").document.images["AnsA"].src="pics/quesButtn/quesBlank_03.gif";
if((parent.frames("question").document.answer2==wronganswer1)||(parent.frames("question").document.answer2==wronganswer2))
parent.frames("question").document.images["AnsB"].src="pics/quesButtn/quesBlank_05.gif";
if((parent.frames("question").document.answer3==wronganswer1)||(parent.frames("question").document.answer3==wronganswer2))
parent.frames("question").document.images["AnsC"].src="pics/quesButtn/quesBlank_08.gif";
if((parent.frames("question").document.answer4==wronganswer1)||(parent.frames("question").document.answer4==wronganswer2))
parent.frames("question").document.images["AnsD"].src="pics/quesButtn/quesBlank_06.gif";
fiftyfiftyUesd=="used";

}
}
</script>
</HEAD>

<a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('fifty','','pics/helpButtn/helpOrange_01.gif',1)" onclick="fiftyfifty()"><img name="fifty" border="0" src="pics/helpButtn/help_01.gif" width="57" height="45"></a>

oldcrazylegs
04-27-2004, 03:10 AM
I raelly don't have an answer for you but maybe you can find it here http://developer.irt.org/script/frame.htm

glenngv
04-27-2004, 04:12 AM
If answer1, answer2, etc are global variables from the frame "question", then the code should be:

if (parent.frames["question"].answer1==wronganswer1 || parent.frames["question"].answer1==wronganswer2)

You may want to store the frame reference to a variable for efficiency.

var qframe = parent.frames["question"];
if (qframe.answer1==wronganswer1 || qframe.answer1==wronganswer2)
...
//change other references to the frame
...

romram
04-27-2004, 06:42 PM
Here is the structure of the frames:



<html>
<head>
<title>Who wants to be a millionaire?</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<frameset rows="330,*" frameborder="NO" border="0" style="margin: 0" >
<frameset cols="*,198" frameborder="NO" >
<frame name=logo scrolling="NO" noresize src="logo.htm">
<frameset rows="50,*" frameborder="NO" >
<frame name=help scrolling="NO" noresize src="help.htm" >
<frame name=score scrolling="NO" noresize src="score.htm">
</frameset>
</frameset>
<frame name="question" scrolling="NO" style="margin:0" src="question.htm">
</frameset>
<noframes>
<body bgcolor="#FFFFFF" text="#000000" >
</body>
</noframes>
</html>



Is there anything that may make the help frame don't recognize the question frame??????

glenngv
04-28-2004, 03:45 AM
Ooh, nested frames! :eek:

Use top.frames instead of parent.frames

var qframe = top.frames["question"];
if (qframe.answer1==wronganswer1 || qframe.answer1==wronganswer2)

Using top goes to the topmost frameset which has the child frame named "help".


FWIW, this is how you access "help" frame from any frame:

top.frames[0].frames[1].frames['help']

or

top.frames[0].frames[1].frames[0]



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum