Click to See Complete Forum and Search --> : global variables
davey
11-09-2003, 11:52 AM
<SCRIPT LANGUAGE="JavaScript">
function myGlobal() {
var global = 5;
function first(param) {
global += 10;
alert(param + " goku's power is " + global);
}
this.first = first;
}
var x = new myGlobal();
</SCRIPT>
when the it goes through the function i want it save
global +=10;
as the new global
any help is very appreciated
Khalid Ali
11-09-2003, 07:10 PM
I think you want something like this
<script type="text/javascript">
<!--
var global=5;
function SetGlobal(param){
global+=param;
return global;
}
function Process(){
alert("Origianl global = "+global+", new global = "+SetGlobal(5));
}
//-->
</script>
</head>
<body class="body">
<input type="button" value="process" onclick="Process()"/>
davey
11-09-2003, 10:19 PM
do you know how i could make the variable appear in a frame?
Khalid Ali
11-09-2003, 10:34 PM
Originally posted by davey
variable appear in a frame?
I am guessing that you meant by above statment "how to access a variable in a frame"?
if true then you first reference to the frameset page that holds all the frames info then you point to the frame where variable actually resides and then you access it
if you had a frame named
leftFrame, and this frame had a variable
var frameVal="Its left Frame";
you can access it from right frame like this
alert(parent.leftFrame.frameVal);
the ablve will show an alert box displaying the var value
davey
11-09-2003, 11:19 PM
is there a way i could view the variable in a form instead of an alert window
Khalid Ali
11-09-2003, 11:22 PM
yes..set the value in the forms text fieldlike this
document.formName.textFieldName.value=parent.leftFrame.frameVal;
davey
11-09-2003, 11:46 PM
i want the global variable
var global=5;
to show up in
<form name="power">
<input name="textfield" type="text" value="HERE" >
</form>
thank you alot
Khalid Ali
11-10-2003, 06:36 AM
try to understand what I wrote above it does exactly what you are asking,(you should be willing to learn rather have some one do it for you)