How to handle multiple event in web control using javascript for ex handling onpaste and on keyup event in textarea
+1
A:
There's no special trick to assigning different event handlers to an element, just define them as you would:
var tArea = document.getElementById("myTextArea");
// Define `onpaste` handler - note that Opera doesn't support `onpaste`
tArea.onpaste = function (evt) {
}
// Define `onkeyup` handler
tArea.onkeyup = function (evt) {
}
If you want to assign multiple functions to the same event, you need to use attachEvent for IE and addEventListener for other browsers.
Andy E
2010-06-15 08:12:11
A:
You can add as many event handlers as you need to an element.
element.addEventListener('event-type', handler1, true);
element.addEventListener('another-type', handler2, true);
element.addEventListener('third-type', handler3, true);
function handler1( e ){}
function handler2( e ){}
function handler3( e ){}
Of course this is different in ie.
element.attachEvent('onevent-type', handler1);
element.attachEvent('onanother-type', handler2);
element.attachEvent('onthird-type', handler3);
so you'll have to code around that or use a library
meouw
2010-06-15 08:13:09