Add multiple functions in javascript

how could I add multiple functions in the fiollowing cases?


myvar.addEventListener("change", functionx, false);
myvar.attachEvent("onchange", functionx);

I tried by just adding more functions after the comma but it is not working

You can instead trigger a different function that itself runs the multiple function you require.

For example:


function changeHandler(evt) {
    functionx();
    functiony();
}
myvar.addEventListener("change", changeHandler, false);

If you want to pass on to those multiple functions the reference to the this keyword, and the changeHandler arguments (that being the evt variable), you can use the apply method to invoke those functions instead:



function changeHandler(evt) {
    functionx.apply(this, arguments);
    functiony.apply(this, arguments);
}
myvar.addEventListener("change", changeHandler, false);