Is this what you meant to do for startup()?
function startup(){
m_XCoord = document.getElementById("t
}
Main Topics
Browse All Topicshere is my main.js
var m_Xcoord
function startup(){
m_XCoord = document.getElementById("t
}
function calc(){
return m_Xcoord * 4
}
here is default.aspx
<head>
<SCRIPT language="JavaScript" src="javascript/main.js" type="text/javascript"></S
</head>
<BODY style="MARGIN: 0px" onload="startUp()" MS_POSITIONING="GridLayout
here is my support.axpx
<head>
<SCRIPT language="JavaScript" src="javascript/main.js" type="text/javascript"></S
</head>
i open both pages in a frameset
when I call calc() from default.aspx it works fine
but then when I call calc() from support.aspx, the m_Xcoord is null
my question:
what is the life or scope of m_Xcoord
why is it null when I call the calc() from support.aspx
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
js file variables gets initialized for each of the page in which they are referensed..
as per ur code :
U r assigning value to m_Xcoord in the onLoad event of default.aspx only not in the other one ( support.axpx)
Does txtXCoord textbox exist in the both pages ???
just remember scope is page... thats why m_Xcoord is null when calc is called from support.aspx
Hi Sonny,
Here is a must read for you: "Accessing Global Variables of Other Pages"
http://www.infimum.dk/HTML
It starts out with "Each page has its own Javascript environment with its own global variables. These are properties of the window object." It then goes on to explain how you CAN access JavaScript variable from another frame. :-)
If you have two frames, named "left" and "right", then to have the page in the "left" frame access a global variable in the "right" frame, the procedure is:
myLeftVariableName = parent.frames["right"].rig
Of course, this is not easily made implicit in order to generalize the code. That is, there's not an easy way to create a single .js file, utilitzing a single set of functions, which can be loaded into frames with arbitrary names and have them access each other's global variables. But at least this shows you that it can be done, and how to do it. :-)
Peace and joy. mvan
Hi Sonny,
Try these files. :-) The same calc() function is called from both frames. The hard coded detail is that the name of the defining frame is "upper". You can see this in main.js
Peace and joy. mvan
----- main.js -----
var m_XCoord;
function startup() {
m_XCoord = document.getElementById("t
}
function calc(){
if (self.frames.name != 'upper') {
return parent.frames['upper'].m_X
} else {
return m_XCoord * 4;
}
}
----- defalut.htm -----
<html>
<head>
<title>mvan - Q_21870468 default.htm</title>
<script language="JavaScript" type="text/javascript" src="javascript/main.js"><
</head>
<BODY style="MARGIN: 0px" onload="startup()">
<input type=textbox name="txtXCoord" id="txtXCoord" value="17"><br>
<input type=button value="calc Test" onclick="alert('default.ht
</BODY>
</html>
----- support.htm -----
<html>
<head>
<title>mvan - Q_21870468 support.htm</title>
<script language="JavaScript" type="text/javascript" src="javascript/main.js"><
</head>
<BODY>
<input type=button value="calc Test" onclick="alert('support.ht
</BODY>
</html>
----- framer.htm -----
<html>
<head>
<title>mvan - Q_21870468 test</title>
</head>
<frameset rows="50%,*">
<frame name="upper" src="default.htm">
<frame name="lower" src="support.htm">
<BODY>
<noframes>This test loads two files into frames</noframes>
</BODY>
</html>
P.S. It could be coded without the frame name, if you depend on the defining frame being the first frame in the frameset, then it is called:
parent.frames[0]
and it's variables are like this:
parent.frames[0].abc
to access:
var abc=33;
for example. The frames are numbered sequentially, starting from 0.
Peace and joy. mvan
Business Accounts
Answer for Membership
by: 0h4crying0utloudPosted on 2006-05-31 at 16:41:20ID: 16803544
What kind of object is "txtXCoord". It seems odd that you are multiplying by 4. Do you mean to get the value of the txtXCoord element?