wrote:
> Hello I was wondering if it was possible to add to an already defined
> onchange event without having to re-write it completely.
>
> scenario:
> <input type="hidden" name="blah" value="" onChange="alert('hello');">
Since this element cannot be edited by the user, and so the `change' event
will never occur for it, the `onChange' attribute (which should be
`onchange') does not make sense here.
That aside:
> <script ...>
> // want to add "world" alert, but since I still want to see
> "hello"...
> document.getElementById("blah").onchange = function()
> {alert("hello");alert("world");}
> </script>
>
> ideally I just want to concatenate like:
> document.getElementById("blah").onchange += function()
> {alert("world");}
Features of the W3C-DOM and DOM Level 0 should not be combined untested;
always avoid such reference worms. Besides, your element has a name, not an
ID. Only MSHTML is this buggy to not care about that difference.
> and not worry about what was there, but then I get a javascript error.
Of course, although "a javascript error" is hardly a viable error
description:
http://www.jibbering.com/faq/faq_not...ml#ps1DontWork
First, probably you have been trying to access properties of a non-object
that document.getElementById() returns here.
Second, you have been trying to concatenate (Function) object references; in
the best case you have been trying to assign the equivalent of
document.getElementById("blah").onchange = NaN;
as the Function objects were converted to their Number representations in
the script engine's attempt to satisfy your nonsensical demand.
As for the latter, you were looking for something along the following instead:
var _global = this, f = obj.onchange;
obj.onchange = function(e)
{
if (!e)
{
e = (typeof _global.window != "undefined"
&& typeof window.event != "undefined"
&& window.event);
}
if (f)
{
f(e);
}
// arbitrary additional code
window.alert("world");
};
// break circular reference to avoid memory leaks in IE
obj = null;
I have implemented this approach in the current version of
_addEventListener() (or dhtml.addEventListener()) in
http://PointedEars.de/scripts/dhtml.js as an alternative to MSHTML's buggy
attachEvent() where EventTarget::addEventListener() from W3C DOM Level 2
Events is not available. Comments are welcome.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16