loosing carriage return and line feed when sending mail by

gajan
gajan used Ask the Experts™
on
Hi,

   I am trying to collect some data in a form and send it through the local email client by predefining to,subject and body. First of all, can this be done using javascript?
  I managed to get the email client(outlook) up with TO and SUBJECT fields properly set but the BODY looses "\r\n" characters which gets inserted in to a textstring variable that inturn gets assigned to the body of the email.

Here's how I do it, checkit gets invoked when you press submit.

function checkit()
{
     // In textstring I gather the data that are finally written to the textarea.

     var textstring = '';
     for (i=0;i<4;i++)
     {
          box = document.forms[0].elements[i];
          textstring += box.name + ': ' + box.value + '\n';
     }
     user_input = '';
     for (i=0;i<document.forms[0].why.length;i++)
     {
          if (document.forms[0].why[i].checked)
          {
               user_input = document.forms[0].why[i].value;
          }
     }
     textstring += 'Why: ' + user_input + "\r\n";



     user_input = document.example.refer.options[document.example.refer.selectedIndex].value
     textstring += 'How: ' + user_input + '\r\n';

     textstring += 'More info: ';
     for (i=9;i<13;i++)
     {
          if (document.example.elements[i].checked)
          {
               textstring += document.example.elements[i].name + ' ';
          }

     }

     // Write textstring to the textarea.

var S="Test"
     document.forms[0].output.value = textstring;

parent.location="mailto:anyone@somewhere.com?subject="+S+"&body="+textstring;
}

Thanks
gajan
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I would not reccomend using mailto.  CGI, perl, or many other server-side solutions would be better.  Perhaps post a 0 point question in those categories pointing to this question?
Commented:
The whole javascript function is just to format the data you post? Otherwise you just could submit your form:

<form name="myForm" action="mailto:anyone@somewhere.com" method="POST">
...
</form>

Before you submit the form (using JavaScript) you could add your subject:

myForm.setAttribute("action","mailto:anyone@somewhere.com" + "?subject=" + subject);
myForm.submit();

Well, i hope this is of any help...

Regards,

Commented:
You could also take a look at the info from microsoft on mailto: http://msdn.microsoft.com/library/default.asp?url=/workshop/networking/predefined/mailto.asp...
You might be able to solve it by finding out the encoded chars for CR+LF...

Regards,
Michel PlungjanIT Expert
Top Expert 2009
Commented:
change

textstring += box.name + ': ' + box.value + '\n';
textstring += 'Why: ' + user_input + "\r\n";

to
textstring += box.name + ': ' + box.value + '%0D%0A';
textstring += 'Why: ' + user_input + '%0D%0A';

Michel PlungjanIT Expert
Top Expert 2009

Commented:
gajan,
No comment has been added lately (86 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: split points between Alopederii http:#7466533 and DTACK http:#7467594 and mplungjan http:#9542273

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

mplungjan
EE Cleanup Volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial