rick wrote:
I found the answer: Do not use 'var' to declare the variable.
Just declare it!! i.e. 'newvar = 0;'
That shouldn't make a difference, if the declaration is not inside a
function body. Then the declaration will declare the global variable,
just as simply assigning to an undeclared variable.
That is what I did. Sorry still learning..........
I think rick is right, declaring a variable without using "var" inside a
function makes the variable global, at least it looks that way to me.
When the button is clicked (see code below) on my IE6, Netscape 7,
Firefox 0.8 the variable 'unknownscopevar' is shown to be initialized.
http://www.southwest.com.au/~jfuller...avascript4.htm
This website makes the claim, 'Generally, variables declared as "var"
are Global variables. Variables declared inside a function as "var" are
local to the function. Variables defined inside a function without the
"var" are Global variables.'
Similar:
http://www.mredkj.com/tutorials/refe..._intro_ex.html
Mike
<script type="text/javascript">
function init() {
unknownscopevar = 'the variable: "unknownscopevar" is initialized';
}
function showvar() {
alert('unkonwnscopevar = '+unknownscopevar);
}
</script>
</head>
<body onload="init()">
<form>
<input type="button" value="Show Variable" onclick="showvar()">
</form>