Stephen Chalmers wrote:
If you use var, it does not create a global variable.
I would expand this note a bit otherwise it may sound like the keyword
"var" by itself doesn't allow to create global variables.
"var" used /within a function/ creates local variable, without "var"
global variable. The fact that many forgets is that intrinsic event
hadlers are anonymous function, so
...onfocus="var Foo='Bar';">
really is
function anonymous(event) {
var Foo='Bar';
}
When present with its "real face" it is obvious that indeed using "var"
within intrinsic event handlers creates local variables for the given
anonymous function.
One have to use it without "var":
...onfocus="Foo='Bar';">
(now Foo is global)
This is a simplified case w/o extra check for IE's issue, so one will
get a script error if the current page contains an element with ID
"Foo".