By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
463,007 Members | 503 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 463,007 IT Pros & Developers. It's quick & easy.

mailto line break question

P: 5
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 = '';
  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
Share this Question
Share on Google+
8 Replies

P: 55
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

P: 5
Thanks, zaphod42

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

Oct 6 '08 #3

Expert Mod 15k+
P: 16,027
I wouldn't recommend mailto unless there's no alternative. Is it not possible to use a server-side language?
Oct 6 '08 #4

P: 5
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

P: 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

Expert Mod 15k+
P: 16,027
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

Expert 100+
P: 303
Can you use %0A? It is the URL encoded linefeed.
Oct 6 '08 #8

Expert Mod 15k+
P: 16,027
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.