I was creating some chat application using JavaScript that allows one to send a message after the enter key is pressed
window.onkeydown=function(event){ if(event.keyCode==13){ sendNew(); } } and in the sendNew() function;
var msg=document.getElementById('txt').value.toString().trim(); if(msg!=="") { //send message document.getElementById('txt').value = ""; } When you press the enter key when the textarea is onfocus the text is cleared but it seems to insert a new line character and the cursor goes to the next line in the textarea.
How can I get rid of this and have a completely empty textarea?