tags:

views:

19

answers:

2

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
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