close

How do I preserve line breaks when getting text from a textarea?

Hello Guys, How are you all? Hope You all Are Fine. Today we are going to learn How do I preserve line breaks when getting text from a textarea? in javascript. So Here I am Explain to you all the possible methods here.

Without wasting your time, Let’s start This Article.

How do I preserve line breaks when getting text from a textarea ?

  1. How do I preserve line breaks when getting text from a textarea ?

    do I preserve line breaks when getting text from a textarea Generally you just need to add
    white-space: pre-line; whitespace trimmed to single whitespace or
    white-space: pre-wrap; all whitespace preserved
    to the element's style (CSS), where you want your text rendered with line-breaks.

  2. How do I preserve line breaks when getting text from a textarea ?

    do I preserve line breaks when getting text from a textarea Generally you just need to add
    white-space: pre-line; whitespace trimmed to single whitespace or
    white-space: pre-wrap; all whitespace preserved
    to the element's style (CSS), where you want your text rendered with line-breaks.

Method 1

Generally you just need to add

  • white-space: pre-line; whitespace trimmed to single whitespace or
  • white-space: pre-wrap; all whitespace preserved

to the element’s style (CSS), where you want your text rendered with line-breaks.

Method 2

You keep output in textarea as it is. You would receive input as a string output that string(write to file) that string adding textarea to the input string.

for eg.
<?php
$txt = $_POST["inputstr"];
$txt1 = "<textarea>". $txt ."</textarea>";
$file = fopen("file.html","a+");
fwrite($file, $txt1);
fclose($file);
?>

Summery

It’s all About this article. Hope all method helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you? Thank You.

Leave a Comment