getting a new line?!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Geoff Cox

    getting a new line?!

    Hello,

    I am trying to get each "Situation - etc" in

    document.getEle mentById("Slide r1ValueText").i nnerHTML
    += escape("\n") + "Situation - " + title[situation_numbe r] + ": ";

    to start on a new line in the email which contains the data sent using
    <form and formmail-nms.cgi.

    I've tried escape("\n") as above, plus \n, \n\r, \\n\\r etc etc but
    cannot get it to work. Ideas please?!

    Cheers

    Geoff


    function saveIt()
    {

    document.getEle mentById("Slide r1ValueText").i nnerHTML = "";

    for (situation_numb er = 0; situation_numbe r < 7; situation_numbe r++)
    {
    document.getEle mentById("Slide r1ValueText").i nnerHTML
    += "Situation - " + title[situation_numbe r] + ": ";

    for (var i = 0; i < slider_value[situation_numbe r].length; i++)
    {
    document.getEle mentById("Slide r1ValueText")
    ..innerHTML += this.slider_val ue[situation_numbe r][i] + ' ';
    }
    }

    var htmlArray = [
    "<form action='http://website/cgi-bin/formmail-nms.cgi'",
    " method='post'>" ,
    "<input type='hidden' name='recipient ' value='extraema ils'>",
    "<input type='hidden' name='realname' value='SPA Form'>",
    "<input type='hidden' name='First name' value='" + firstname + "'>",
    "<input type='hidden' name='Last name' value='" + lastname + "'>",
    "<input type='hidden' name='Slider Values' value='" +
    document.getEle mentById('Slide r1ValueText').i nnerHTML + "'>",
    "<input type='submit' value='send'></form>"
    ];


    document.getEle mentById("formd ata").innerHTM L = htmlArray.join( ' ');

    var subForm = document.getEle mentById("formd ata");
    subForm = document.getEle mentsByTagName( 'FORM')[0];
    subForm.submit( );

    }
  • Baconbutty

    #2
    Re: getting a new line?!

    Assuming your e-mail is in HTML format..

    I don't think \n is preserved in HTML unless it is in a <PRE> element,
    or you have "white-space:pre" set.

    Try inserting "<BR>" instead.

    Comment

    • Geoff Cox

      #3
      Re: getting a new line?!

      On 4 Oct 2005 00:45:01 -0700, "Baconbutty " <julian@baconbu tty.com>
      wrote:
      [color=blue]
      >Assuming your e-mail is in HTML format..
      >
      >I don't think \n is preserved in HTML unless it is in a <PRE> element,
      >or you have "white-space:pre" set.
      >
      >Try inserting "<BR>" instead.[/color]

      Hello,

      I will try that in a second but have just noticed that if I use "\n"
      with Firefox I get the new line whereas I do not get it with Internet
      Explorer !!??

      Cheers

      Geoff

      Comment

      • Geoff Cox

        #4
        Re: getting a new line?!

        On 4 Oct 2005 00:45:01 -0700, "Baconbutty " <julian@baconbu tty.com>
        wrote:
        [color=blue]
        >Assuming your e-mail is in HTML format..
        >
        >I don't think \n is preserved in HTML unless it is in a <PRE> element,
        >or you have "white-space:pre" set.
        >
        >Try inserting "<BR>" instead.[/color]

        have just tried the <BR> and no go! Odd how the 2 different browsers
        affect this?

        Geoff

        Comment

        • Baconbutty

          #5
          Re: getting a new line?!

          Sorry, I have not read your code as thoroughly as I should.
          [color=blue]
          >input type='hidden' name='Slider Values' value='" +
          >document.getEl ementById('Slid er1ValueText'). innerHTML[/color]

          If I understand it correctly it looks like you are creating a list of
          items, separated by "%0A" (or "%OD"), and making this the value of the
          hidden input, so my BR suggestion could have been rubbish, particularly
          as it involves puting markup in an attribute value.

          I don't know what you are doing server side, but have you tried
          unescaping the value when it is received by the server?
          [color=blue]
          >document.getEl ementById("Slid er1ValueText"). innerHTML[/color]

          Also, why are you using an element for storage, when you could just use
          a string variable in script - am I missing something?

          Comment

          • Baconbutty

            #6
            Re: getting a new line?!

            Back to my original point - what is the format of the e-mail?

            If the e-mail is HTML format, then "\n" is usually stripped out as
            whitespace. In which case if you are sending mark-up to the server,
            you may as well escape the whole of
            "document.getEl ementById('Slid er1ValueText'). innerHTML".

            If the e-mail is plain text, then you will need to unescape the \n on
            the server.

            Comment

            • Geoff Cox

              #7
              Re: getting a new line?!

              On 4 Oct 2005 03:28:48 -0700, "Baconbutty " <julian@baconbu tty.com>
              wrote:
              [color=blue][color=green]
              >>document.getE lementById("Sli der1ValueText") .innerHTML[/color]
              >
              >Also, why are you using an element for storage, when you could just use
              >a string variable in script - am I missing something?[/color]

              More lilely to be me that's missing something! Are you saying that I
              do not need to use either

              document.getEle mentById("Slide r1ValueText").i nnerHTML

              or

              document.getEle mentById("formd ata").innerHTM L

              ?? and that I could use string variables??

              Cheers

              Geoff




              function saveIt()
              {

              mySlider1.setVa lue( (mySlider1.left Value +
              mySlider1.right Value) / 2 );

              document.getEle mentById("Slide r1ValueText").i nnerHTML = "";

              for (situation_numb er = 0; situation_numbe r < 7;
              situation_numbe r++)
              {

              document.getEle mentById("Slide r1ValueText").i nnerHTML +=
              "<br>" + "Situation - " + title[situation_numbe r] + ": ";

              for (var i = 0; i <
              slider_value[situation_numbe r].length; i++)
              {
              document.getEle mentById("Slide r1ValueText").i nnerHTML
              += this.slider_val ue[situation_numbe r][i] + ' ';
              }
              }

              var htmlArray = [
              "<form action='http://websitecgi-bin/formmail-nms.cgi'",
              " method='post'>" ,
              "<input type='hidden' name='recipient ' value='extraema ils'>",
              "<input type='hidden' name='realname' value='SPA Form'>",
              "<input type='hidden' name='First name' value='" + firstname
              + "'>",
              "<input type='hidden' name='Last name' value='" + lastname +
              "'>",
              "<input type='hidden' name='Slider Values' value='" +
              document.getEle mentById('Slide r1ValueText').i nnerHTML + "'>",
              "<input type='submit' value='send'></form>"
              ];


              document.getEle mentById("formd ata").innerHTM L = htmlArray.join( ' ');

              var subForm = document.getEle mentById("formd ata");
              subForm = document.getEle mentsByTagName( 'FORM')[0];
              subForm.submit( );

              }

              function sendbutton()
              {
              document.getEle mentById('sendb utton').innerHT ML = "<input
              type='button' name ='nextbutton' value='Next'
              onclick='next_q uestion(this)'> ";
              }

              Comment

              • Baconbutty

                #8
                Re: getting a new line?!

                >document.getEl ementById("Slid er1ValueText"). innerHTML[color=blue]
                >or
                >document.getEl ementById("form data").innerHTM L[/color]

                Just the former - I am not sure why you need Slider1ValueTex t. The
                latter is needed because it is the container for your manufactured
                form.
                [color=blue][color=green]
                >>?? and that I could use string variables??[/color][/color]

                I may be off the mark, and you may be using the Slider1ValueTex t
                element to see what you are doing, but you could try:-

                function saveIt()
                {
                mySlider1.setVa lue( (mySlider1.left Value +
                mySlider1.right Value) / 2 );

                //document.getEle mentById("Slide r1ValueText").i nnerHTML = "";
                var sValue="";

                for (situation_numb er = 0; situation_numbe r < 7;
                situation_numbe r++)
                {

                // CHOICE COULD DEPEND ON WHAT FORMAT IS EXPECTED AT THE
                SERVER
                //sValue+="<br>" + "Situation - " +
                title[situation_numbe r] + ": ";
                sValue+="\n" + "Situation - " + title[situation_numbe r] +
                ": ";

                for (var i = 0; i <
                slider_value[situation_numbe r].length; i++)
                {
                sValue+=this.sl ider_value[situation_numbe r][i] +
                ' ';
                }
                }

                // USE IF YOU WANT TO DISPLAY IT
                //document.getEle mentById("Slide r1ValueText").i nnerHTML = sValue;


                // I WOULD THEN TRY UNESCAPING IN YOUR CGI SCRIPT
                sValue=escape(s Value);

                var htmlArray = [
                "<form action='http://websitecgi-bin/formmail-nms.cgi'",
                " method='post'>" ,
                "<input type='hidden' name='recipient ' value='extraema ils'>",
                "<input type='hidden' name='realname' value='SPA Form'>",
                "<input type='hidden' name='First name' value='" + firstname
                + "'>",
                "<input type='hidden' name='Last name' value='" + lastname +
                "'>",
                "<input type='hidden' name='Slider Values' value='" + sValue
                + "'>",
                "<input type='submit' value='send'></form>"
                ];


                document.getEle mentById("formd ata").innerHTM L = htmlArray.join( ' ');

                var subForm = document.getEle mentById("formd ata");
                subForm = document.getEle mentsByTagName( 'FORM')[0];
                subForm.submit( );

                }

                Comment

                • Geoff Cox

                  #9
                  Re: getting a new line?!

                  On 4 Oct 2005 06:41:21 -0700, "Baconbutty " <julian@baconbu tty.com>
                  wrote:

                  Julian,

                  I have tried your code using the sValue variable etc and 1 step
                  forward at least - both Internet Explorer and Firefox give the same
                  email result !

                  Trouble is I am not getting the newline - I see %0ASituation in the
                  email. Where now?!

                  Cheers

                  Geoff

                  I guess for clarity I had better add the code which I used ...


                  function saveIt()
                  {
                  mySlider1.setVa lue( (mySlider1.left Value +
                  mySlider1.right Value) / 2 );

                  //document.getEle mentById("Slide r1ValueText").i nnerHTML = "";
                  var sValue="";

                  for (situation_numb er = 0; situation_numbe r < 7;
                  situation_numbe r++)
                  {
                  // CHOICE COULD DEPEND ON WHAT FORMAT IS EXPECTED AT THE
                  SERVER
                  //sValue+="<br>" + "Situation - " +
                  title[situation_numbe r] + ": ";
                  sValue+="\n" + "Situation - " + title[situation_numbe r]
                  + ": ";

                  for (var i = 0; i <
                  slider_value[situation_numbe r].length; i++)
                  {
                  sValue+=this.sl ider_value[situation_numbe r][i] + ' ';
                  }
                  }

                  // USE IF YOU WANT TO DISPLAY IT
                  //document.getEle mentById("Slide r1ValueText").i nnerHTML =
                  sValue;

                  // I WOULD THEN TRY UNESCAPING IN YOUR CGI SCRIPT

                  sValue=escape(s Value);

                  var htmlArray = [
                  "<form action='http://website/cgi-bin/formmail-nms.cgi'",
                  " method='post'>" ,
                  "<input type='hidden' name='recipient ' value='extraema ils'>",
                  "<input type='hidden' name='realname' value='SPA Form'>",
                  "<input type='hidden' name='First name' value='" + firstname +
                  "'>",
                  "<input type='hidden' name='Last name' value='" + lastname +
                  "'>",
                  "<input type='hidden' name='Slider Values' value='" + sValue +
                  "'>",
                  "<input type='submit' value='send'></form>"
                  ];


                  document.getEle mentById("formd ata").innerHTM L = htmlArray.join( ' ');

                  var subForm = document.getEle mentById("formd ata");
                  subForm = document.getEle mentsByTagName( 'FORM')[0];
                  subForm.submit( );

                  }

                  Comment

                  • Baconbutty

                    #10
                    Re: getting a new line?!

                    >Trouble is I am not getting the newline - I see %0ASituation in the[color=blue]
                    >email. Where now?![/color]

                    You need to "unescape" the input value on th server.

                    I.e you are sending the string " %0ASituation" to the server.

                    The following script:-

                    "http://website/cgi-bin/formmail-nms.cgi'"

                    needs to use "unescape" (or cgi equivalent) to convert %OA -> to
                    newline character.

                    Comment

                    • Geoff Cox

                      #11
                      Re: getting a new line?!

                      On 4 Oct 2005 07:49:29 -0700, "Baconbutty " <julian@baconbu tty.com>
                      wrote:
                      [color=blue][color=green]
                      >>Trouble is I am not getting the newline - I see %0ASituation in the
                      >>email. Where now?![/color]
                      >
                      >You need to "unescape" the input value on th server.
                      >
                      >I.e you are sending the string " %0ASituation" to the server.
                      >
                      >The following script:-
                      >
                      >"http://website/cgi-bin/formmail-nms.cgi'"
                      >
                      >needs to use "unescape" (or cgi equivalent) to convert %OA -> to
                      >newline character.[/color]

                      Julian,

                      I has just occurred to me that I am wrong! The newline is being acted
                      on when using both IE and Firefox - in that the word "Situation" does
                      start on a newline each time. The strange thing is that with Firefox
                      0D0A gets into other parts of the lines disrupting the format. How can
                      that be happening?!

                      Cheers

                      Geoff


                      1. IE

                      Situation - Social Individual: 3 3 3 3 3 3 3 3
                      Situation - Formal Individual: 3 3 3 3 3 3 3 3
                      Situation - Social Group: 3 3 3 3 3 3 3 3
                      Situation - Formal Group: 3 3 3 3 3 3 3 3
                      Situation - Parents: 3 3 3 3 3 3 3 3
                      Situation - Telephone: 3 3 3 3 3 3 3 3
                      Situation - 'Scripted' Conversations: 3 3 3 3 3 3 3 3

                      2. Firefox

                      Situation - Social Individual: 3 3 3 3 3 3 3 3
                      Situation - Formal
                      Individual: 3 3 3 5 3 3 3 3
                      Situation - Social Group:3 3 3 3 3 3 3 3

                      Situation - Formal Group: 3 3 3 3 3 3 3 3
                      Situation - Parents:3 3
                      3 3 3 3 3 3
                      Situation - Telephone: 3 3 3 3 3 3 3 3
                      Situation -
                      'Scripted' Conversations:3 3 3 3 3 3 3 3




                      Comment

                      • Geoff Cox

                        #12
                        Re: getting a new line?!

                        On 4 Oct 2005 07:49:29 -0700, "Baconbutty " <julian@baconbu tty.com>
                        wrote:

                        Julian,

                        I need to correct what I said last !!

                        When I use you last code with the sValue etc - if I remove the
                        escape(sValue) I get the correct format using both IE and Firefox !!

                        So it looks as if the problem may be caused by my use of
                        prototype-1.3.1.js in the other version of this app where I still get
                        the different formatting with the 2 browsers. Problem here seems to be
                        that it is difficult to get any help with prototype. Have you ever
                        used it?


                        Geoff

                        Comment

                        • Baconbutty

                          #13
                          Re: getting a new line?!

                          >When I use you last code with the sValue etc - if I remove the[color=blue]
                          >escape(sValu e) I get the correct format using both IE and Firefox !![/color]

                          Great. So is it working then? Sorry that it has been a little
                          difficult to advise, as I do not have the full client/server context in
                          which the code is running.
                          [color=blue]
                          >So it looks as if the problem may be caused by my use of
                          >prototype-1.3.1.js in the other version of this app where I still get
                          >the different formatting with the 2 browsers. Problem here seems to be
                          >that it is difficult to get any help with prototype. Have you ever
                          >used it?[/color]

                          Sorry, not really looked at this. However, scanning it quickly, it all
                          looks familiar. I have (as I am sure have most) over the last couple
                          of years created my own library of some 500 functions, doing pretty
                          much the same things.

                          If you think there is a problem with a particular element of
                          prototype.js, you could always post this.

                          Comment

                          • Geoff Cox

                            #14
                            Re: getting a new line?!

                            On 5 Oct 2005 02:28:10 -0700, "Baconbutty " <julian@baconbu tty.com>
                            wrote:
                            [color=blue]
                            >Sorry, not really looked at this. However, scanning it quickly, it all
                            >looks familiar. I have (as I am sure have most) over the last couple
                            >of years created my own library of some 500 functions, doing pretty
                            >much the same things.
                            >
                            >If you think there is a problem with a particular element of
                            >prototype.js , you could always post this.[/color]

                            Julian,

                            I would like to narrow down the problem but at moment all I can see is
                            that when using prototype-1.3.1js in the code the two browsers treat
                            the email data format differently whereas with your code they both
                            look the same.

                            Not sure that I can do better!?

                            Cheers

                            Geoff

                            Comment

                            • Baconbutty

                              #15
                              Re: getting a new line?!

                              OK. Looks like thats it then.

                              Cheers

                              Julian

                              Comment

                              Working...