function encode(r) {_x000D_
return r.replace(/[\x26\x0A\x3c\x3e\x22\x27]/g, function(r) {_x000D_
return "&#" + r.charCodeAt(0) + ";";_x000D_
});_x000D_
}_x000D_
_x000D_
test.value=encode('How to encode\nonly html tags &<>\'" nice & fast!');_x000D_
_x000D_
/*_x000D_
\x26 is &ersand (it has to be first),_x000D_
\x0A is newline,_x000D_
\x22 is ",_x000D_
\x27 is ',_x000D_
\x3c is <,_x000D_
\x3e is >_x000D_
*/
_x000D_
<textarea id=test rows=11 cols=55>www.WHAK.com</textarea>
_x000D_