Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
173
rated 0 times [  180] [ 7]  / answers: 1 / hits: 124847  / 15 Years ago, wed, january 20, 2010, 12:00:00

I have a textarea, On every Enter key pressed in textarea 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 textarea and append * to it and again fill the textarea ?


More From » textarea

 Answers
67

You could do something like this:



<body>

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

<script>
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;
}
}
</script>

</body>


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


[#97789] Saturday, January 16, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
julieth

Total Points: 382
Total Questions: 99
Total Answers: 85

Location: Cape Verde
Member since Fri, Nov 27, 2020
4 Years ago
julieth questions
;