F
fxn
I want to add programmatically a function call to some onkeypress,
taking into account that perhaps it already has something assigned.
This addition is done on window load with the following code (it has
some Prototype mixed in but it is minimal):
function add_autofit() {
$$('.autofit').each(function (e) {
var atf = function (input) { autofit(input); };
var current_onkeypress = Prototype.emptyFunction;
if (e.onkeypress)
current_onkeypress = e.onkeypress;
e.onkeypress = function () { current_onkeypress(this);
atf(this); };
autofit(e);
});
}
Event.observe(window, 'load', add_autofit);
Looks like I don't understand the scope of this, because autofit
alerts it has received the window object as input. I do not know how
to get that right, would you help please?
-- fxn
PS: I am not using listeners because I need to invoke onchange
programmatically afterwards.
taking into account that perhaps it already has something assigned.
This addition is done on window load with the following code (it has
some Prototype mixed in but it is minimal):
function add_autofit() {
$$('.autofit').each(function (e) {
var atf = function (input) { autofit(input); };
var current_onkeypress = Prototype.emptyFunction;
if (e.onkeypress)
current_onkeypress = e.onkeypress;
e.onkeypress = function () { current_onkeypress(this);
atf(this); };
autofit(e);
});
}
Event.observe(window, 'load', add_autofit);
Looks like I don't understand the scope of this, because autofit
alerts it has received the window object as input. I do not know how
to get that right, would you help please?
-- fxn
PS: I am not using listeners because I need to invoke onchange
programmatically afterwards.