1

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 breaks and I also don't want to use all other present text editors 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.

4
  • Are you in control of the backend? Commented Apr 4, 2012 at 3:08
  • yes, actually i want the text editor to be in the backend. Commented Apr 4, 2012 at 3:15
  • I mean, do you have access to the code that saves the data in the database? Commented Apr 4, 2012 at 3:19
  • Yes. its my own page. I am developing it. I want my backend to be friendly to me. Commented Apr 4, 2012 at 3:23

2 Answers 2

3
<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>
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.