I am trying to create a simple javascript text editor that only makes paragraph breaks to entered paragraphs inside textarea input. while saving textarea input value in database they strip out the paragraph breakings and I also don't want to use all other present texteditors because I only need the paragraph breaking (br tag) to be placed while hit enter key and should be saved like that with the tag inside the database. I could not find the solution by googling.
<textarea id="txtArea" onkeypress="onKeyDown();"></textarea>
<script>
function onKeyDown() {
var key = window.event.keyCode;
// If the user has pressed enter
if (key == 13) {
alert('enter');
return false;
}
else {
return true;
}
}
</script>
Depending on your needs, you may consider using something to replace newlines with <br>
tags on the server side rather than trying to insert the tags in the textarea itself. PHP has the nl2br function for example.