var str = document.all.textarea.value; str = str.replace(/\r\n/ig,"<br/>"); str = str.replace(/\s+/g," "); alert(str);