Simply:
document.getElementById('chatboxtextarea').onkeyup = function (e) {
e = e || window.event;
var textarea = this;
var msg = textarea.value;
if (msg.replace(/\r/g, '\\\\r').replace(/\n/g, '') != "" && e.keyCode == 13) {
textarea.value = '';
.....code to send.....
} else if (msg.replace(/\r/g, '\\\\r').replace(/\n/g, '') == '') {
textarea.value = '';
}
};
change
Alternatively, you can call something like the following to add an event; passing an element object, an event type (without 'on'), a call function, and using capture to use various browser methods:
function addEvent(elm, evType, fn, useCapture) {
if (elm.addEventListener) {
elm.addEventListener(evType, fn, useCapture);
}
else if (elm.attachEvent) {
elm.attachEvent('on' + evType, fn);
}
else {
elm['on' + evType] = fn;
}
};
t
addEvent(document.getElementById('chatboxtextarea'), 'keyup',
function(e) {
e = e || window.event;
...
}, false);
source
share