mailto line break question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mkalex
    New Member
    • Oct 2008
    • 5

    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?

    Code:
    function SendEmail()
    {
        var dept = 'department';
        var toaddy = 'X@xxx.com';
    	var subject = 'Contact Us Reply';
    	var mailer = 'mailto:' + toaddy + '?subject=' + subject + '&body=' + 
    'Name%20is:%20' +  document.jsform.visitorname.value  + "" +
    'Request%20is:%20' + document.jsform.department.value + "" +
    'Comments%20are:%20\n' + document.jsform.message.value + "" ;
    	parent.location = mailer; 
    } // -->
    Thanks.
    --MK
    PS I'm in a MacOS environment and I'm testing this in MacMail.
    Last edited by acoder; Oct 6 '08, 10:17 AM. Reason: Added [code] tags
  • zaphod42
    New Member
    • Oct 2008
    • 55

    #2
    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

    Comment

    • mkalex
      New Member
      • Oct 2008
      • 5

      #3
      Thanks, zaphod42

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

      --MK

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        I wouldn't recommend mailto unless there's no alternative. Is it not possible to use a server-side language?

        Comment

        • mkalex
          New Member
          • Oct 2008
          • 5

          #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.

          --MK

          Comment

          • mkalex
            New Member
            • Oct 2008
            • 5

            #6
            Never mind...

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

            Thanks, though

            --MK

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              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 encodeURICompon ent(), or using String.fromChar Code(10) and 13.

              Comment

              • improvcornartist
                Recognized Expert Contributor
                • May 2007
                • 303

                #8
                Can you use %0A? It is the URL encoded linefeed.

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  That makes sense, and that is indeed what encodeURICompon ent("\n") produces. If you want a carriage return too, add %0D

                  Comment

                  Working...