Home > Software engineering >  Add a Line Break In HTML Email
Add a Line Break In HTML Email

Time:02-25

I have made a request form for my work and it working as expected. I have placed some text in the text area as a hide/show for users. On the visual studio code, I see the line breaks fine but when I submit the form and the recipient gets the email all that was in the text area is all in one line instead of line break where I wanted.

Also how to kill the extra white spaces. Also have used this

Is there any fix to this?

I get this in email DC GM Groups Domain Group Access:  All Folders and Drives Required Distribution List:  All Emails

Tried everything I could research but doesn't seem to work

white-space: nowrap;
text-align: left;
width: 650px;
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div >
  <!-- style="visibility:hidden;" -->
  <!-- acc means account -->
  <textarea  id="acc_GMGroup" name="acc_GMGroup" rows="10">
Domain Group Access:&#13;&#10;&emsp;All Folders and Drives Required&#13;&#10;
Distribution List:&#13;&#10;&emsp;All Emails

                            </textarea>
</div>

CodePudding user response:

To answer your first two questions

The easiest way to format like it is in the text area is to put the text between <pre>...</pre> tags

The other thing you could do is use regular expressions to switch from text to html, like

text.replace(/[\n]/g,"<br>");
text.replace(/\s\s /g,function(part) {
  return part.substring(0,1);
}));

CodePudding user response:

A textarea will render whitespace as it was entered into the element so just format the whitespace by literally adding it.

<div >
  <textarea  id="acc_GMGroup" name="acc_GMGroup" rows="10">
Domain Group Access:
 All Folders and Drives Required
 
Distribution List:
 All Emails
  </textarea>
</div>

  • Related