1

I am creating a form for medical prescription. Here one of the textarea field name is new prescription. Doctor will insert value here like

1. medicine-l
   1+1+1
2. medicine-2
   1+0+1

But while I print out the prescription this new prescription field shows it's value like

1.medicine-1 1+1+1 2.medicine-2 1+0+1

But I want to printout the value of new prescription just like how doctor inserted.

How can I do it? Anybody Help Please ?

Arafat Rahman
  • 993
  • 5
  • 19
  • 46
  • Possible duplicate of [how do you strip html tags in textarea input](https://stackoverflow.com/questions/12022614/how-do-you-strip-html-tags-in-textarea-input) – Satish Saini Feb 17 '19 at 05:50
  • 1
    This is not asking how to strip tags. –  Feb 17 '19 at 06:15

2 Answers2

1

The line breaks are actually preserved untill you print the text out. HTML doesn't doesn't detect the line breaks in the text.

Try this for JS:

textAreaText.replace(/(?:\r\n|\r|\n)/g, '<br>');

How do I replace all line breaks in a string with <br /> tags?

Try this for PHP : http://php.net/manual/en/function.nl2br.php

SSG
  • 100
  • 7
0

You should be able to do this using the CSS property white-space.

Example:

.textarea-class {
  white-space: pre-wrap;
}

Consult the MDN docs for a very nice overview if the various options, but it seems like you want either pre (just as it is), pre-wrap (maintains spacing and line breaks, but wraps), or even pre-line (maintains line breaks but not spacing, and wraps).

You’ll want to put this in your print stylesheet.