F
fxn
Coming from the need to chain callbacks dynamically, and following
Flanagan's book on this, I've narrowed my misunderstanding to this
self-contained example:
<html>
<head>
<script type="text/javascript" charset="utf-8">
function test_this() {
var foo = document.getElementById("foo");
foo.onkeypress = function () { alert_this(); }
}
function alert_this() {
alert(this);
}
</script>
</head>
<body onload="test_this()">
Foo: <input type="text" id="foo">
</body>
</html>
The alert says this is window, why? And how would you program that so
that you get the textfield in alert_this?
-- fxn
Flanagan's book on this, I've narrowed my misunderstanding to this
self-contained example:
<html>
<head>
<script type="text/javascript" charset="utf-8">
function test_this() {
var foo = document.getElementById("foo");
foo.onkeypress = function () { alert_this(); }
}
function alert_this() {
alert(this);
}
</script>
</head>
<body onload="test_this()">
Foo: <input type="text" id="foo">
</body>
</html>
The alert says this is window, why? And how would you program that so
that you get the textfield in alert_this?
-- fxn