...

View Full Version : Getting variables to new frame from function!



macman012
08-27-2007, 01:38 AM
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.)

Arty Effem
08-27-2007, 03:27 AM
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:

myVar=parent.frames.otherFrameName.variableName
To access the return value of a function in the other frame, try:

myVar=parent.frames.otherFrameName.functionName();

glenngv
08-27-2007, 07:30 AM
myVar=parent.frames["targetFrameName"].variableName;
myVar=parent.frames["targetFrameName"].functionName();



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum