Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Apr 2004
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing variables from one frame to another

    I have write code to use variable from another frame, but the code didn't work?
    Code:
    <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>

  • #2
    Regular Coder oldcrazylegs's Avatar
    Join Date
    Feb 2004
    Location
    East Moline Illinois USA
    Posts
    414
    Thanks
    4
    Thanked 5 Times in 4 Posts
    I raelly don't have an answer for you but maybe you can find it here http://developer.irt.org/script/frame.htm

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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
    ...
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #4
    New Coder
    Join Date
    Apr 2004
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is the structure of the frames:

    Code:
    <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??????

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Ooh, nested frames!

    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]
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •