sat sat - 6 months ago 45
Javascript Question

Enter key in textarea

I have a

, On every Enter key pressed in
I want new line to be started with a bullet say (*). How to go about it ?

No jQuery please.

I can observe for the Enter key , after that !? Should I have to get the whole value of
and append * to it and again fill the


You could do something like this:


<textarea id="txtArea" onkeypress="onTestChange();"></textarea>

function onTestChange() {
    var key = window.event.keyCode;

    // If the user has pressed enter
    if (key === 13) {
        document.getElementById("txtArea").value = document.getElementById("txtArea").value + "\n*";
        return false;
    else {
        return true;


Although the new line character feed from pressing enter will still be there, but its a start to getting what you want.