471,863 Members | 1,117 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,863 software developers and data experts.

mailto line break question

Hi All,
Great site BTW!
OK, I'm very new at this so forgive me ignorance, please!

I have a little JS that emails elements from a form; name, choice from a drop-down list, and "comments". It all works fine except that when it dumps the results into the body of the email, there are no line breaks.
I tried adding + "\r" and "\n" with no improvement. I'm guess the script is sending plain text at this point. Is there any way to embed an ascii code for carriage return in the + "" section of this code?

Expand|Select|Wrap|Line Numbers
  1. function SendEmail()
  2. {
  3.     var dept = 'department';
  4.     var toaddy = 'X@xxx.com';
  5.     var subject = 'Contact Us Reply';
  6.     var mailer = 'mailto:' + toaddy + '?subject=' + subject + '&body=' + 
  7. 'Name%20is:%20' +  document.jsform.visitorname.value  + "" +
  8. 'Request%20is:%20' + document.jsform.department.value + "" +
  9. 'Comments%20are:%20\n' + document.jsform.message.value + "" ;
  10.     parent.location = mailer; 
  11. } // -->
PS I'm in a MacOS environment and I'm testing this in MacMail.
Oct 5 '08 #1
8 4760
did you try "/n/r" ?
"/n" creates a new line, but you need "/r" to come after it to move your point of refence to the new line
Oct 5 '08 #2
Thanks, zaphod42

I did try "/n/r" or rather "\n\r" with no result.

Oct 6 '08 #3
16,027 Expert Mod 8TB
I wouldn't recommend mailto unless there's no alternative. Is it not possible to use a server-side language?
Oct 6 '08 #4
Thanks for the reply Acoder,

You are of course correct, a server side mailer would be better; yet my curiosity is piqued. If I get an answer here on this forum, I will have abetter understanding of javascript.

Oct 6 '08 #5
Never mind...

I solved my problem with "\u2029"
It allows me to add a paragraph anywhere I need.

Thanks, though

Oct 6 '08 #6
16,027 Expert Mod 8TB
Good job. If you escape the line break, you could probably use it in your code, though I haven't tested, e.g. by using encodeURIComponent(), or using String.fromCharCode(10) and 13.
Oct 6 '08 #7
303 Expert 100+
Can you use %0A? It is the URL encoded linefeed.
Oct 6 '08 #8
16,027 Expert Mod 8TB
That makes sense, and that is indeed what encodeURIComponent("\n") produces. If you want a carriage return too, add %0D
Oct 6 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

15 posts views Thread by nAmYzArC | last post: by
19 posts views Thread by Philipp Lenssen | last post: by
15 posts views Thread by Val | last post: by
9 posts views Thread by Adi | last post: by
5 posts views Thread by Joh | last post: by
10 posts views Thread by Itaichuk | last post: by
3 posts views Thread by fiefie.niles | last post: by
6 posts views Thread by Mike | last post: by
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.