Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Text to Email Body with Carriage Returns

Status
Not open for further replies.

hungerf5

IS-IT--Management
Sep 17, 2001
36
US
I'm having difficulty passing text to the body of an email with carriage returns.

I have a page that passes checkbox values from one form to the other with each value on its own line. The form that received the values then generates an email. The problem is once the data is pushed into the email the lines become merged together.

Any suggestions on who to keep the lines separate in the body of the email? Is there a way to read TEXTAREA line by line?

Below is the Code:

<html>
<head>

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function PopulateBody() {
output = ''
for(i=0; i < document.Parts.checkbox.length; i++)
{
if (document.Parts.checkbox.checked)
{
output += document.Parts.checkbox.value + '\r' ;
}
}
document.eMail.body.value = output;
}

function MailIt()
{
var S=document.eMail.subject.value;
var B=document.eMail.body.value;
self.location=&quot;mailto:someone@somewhere.com?subject=&quot;+S+&quot;&body=&quot;+B;
}

// End -->
</SCRIPT>


<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>

<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
<form name=&quot;Parts&quot;>
<p>This form populates the one below with only the checked checkboxes</p>
<p>
<input type=&quot;checkbox&quot; name=&quot;checkbox&quot; value=&quot;A&quot;>
A<br>
<input type=&quot;checkbox&quot; name=&quot;checkbox&quot; value=&quot;B&quot;>
B<br>
<input type=&quot;checkbox&quot; name=&quot;checkbox&quot; value=&quot;C&quot;>
C<br>
<input type=&quot;checkbox&quot; name=&quot;checkbox&quot; value=&quot;D&quot;>
D<br>
<input type=&quot;button&quot; name=&quot;Submit&quot; value=&quot;Populate Body&quot; onClick=&quot;PopulateBody()&quot;>
</p>
</form>

<form name=&quot;eMail&quot; method=&quot;post&quot; ENCTYPE=&quot;text/plain&quot;>
Email Form
<p>Recipient
<input type=&quot;text&quot; name=&quot;Recipient&quot;>
<br>
Subject
<input type=&quot;text&quot; name=&quot;subject&quot; value=&quot;No Subject&quot;>
<br>
<textarea name=&quot;body&quot; cols=&quot;50&quot; rows=&quot;10&quot; wrap=&quot;OFF&quot;></textarea>
</p>
<p>
<input type=&quot;button&quot; name=&quot;Submit2&quot; value=&quot;Submit&quot; onClick=&quot;MailIt()&quot;>
</p>
</form>
</body>
</html>
 
This is known problem. You have to convert all carriage return chars to <br> if you pass the text to html or to &quot;\n&quot; if you pass it to javascript string.

Here's a script that does this:
I used it myself once.

Search this forum for &quot;convert carriage return&quot; and you'll find many threads about it.


Anyway, I don't think that it worth doing as it doesn't work with all email clients, and depends on client javascript on/off and default mailer.

good luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top