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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Getting variables to new frame from function!

    I have a Javascript page that consists of 2 frames, an upper and a lower. In the lower I have some functions that use Variable++ to increment a variable in a loop based on user actions. When this loop is done, I want to be able to access the final value of this variable in the upper frame. I have tried using things such as window.top.fraLowerWindow.function().variable.value, but I get the error "window.top.fraLowerWindow.function() is not a function." Any suggestions?

    Example:

    function WinMessage()
    {
    alert("Congrats, you have clicked the dot and scored a point!");
    Clicks++;
    }

    How would I access the variable Clicks in another frame? (It is in a loop, and I want to access the final value when the loop is done.)

  • #2
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by macman012 View Post
    I have tried using things such as window.top.fraLowerWindow.function().variable.value, but I get the error "window.top.fraLowerWindow.function() is not a function." Any suggestions?

    Example:

    function WinMessage()
    {
    alert("Congrats, you have clicked the dot and scored a point!");
    Clicks++;
    }

    How would I access the variable Clicks in another frame? (It is in a loop, and I want to access the final value when the loop is done.)
    You haven't shown where Clicks is declared. If it's a private variable, you can't access it outside the function, let alone another frame.

    To access a global variable in the other frame:
    Code:
    myVar=parent.frames.otherFrameName.variableName
    To access the return value of a function in the other frame, try:
    Code:
    myVar=parent.frames.otherFrameName.functionName();
    Last edited by Arty Effem; 08-28-2007 at 01:11 AM.

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Code:
    myVar=parent.frames["targetFrameName"].variableName;
    myVar=parent.frames["targetFrameName"].functionName();


  •  

    Posting Permissions

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