Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    MAILTO + Javascript

    Before I begin I know - bad idea - but this is for work and will be used on our intranet in a closed environment where everyone is using IE7 and Outlook.

    I have created an online quiz (HTML + Javascript) and the result is that the answers are forwarded to the email of the inputted trainers email.

    Problem:
    The plain/text output to the email does not have spaces or carriage returns between the answers. So the answers sometimes look like a big block of characters.

    Request:
    To add some javascript which will work within my existing code to add a space after each response. I know it should be r/ or %20 but I dont seem to know enough to make it work.

    Code:
    	<FORM NAME="mailer" id="frm" METHOD="post" ACTION="" ENCTYPE="text/plain" onSubmit="(document.mailer.action += mailtoandsubject)" >
    
                 <div style="background-color:#efefef;border:1px solid #ccc;height:30px; margin-bottom:10px; padding:5px;">   
    			<h2>Before you begin please enter the email of your Supervisor or Trainer:</span> <input  type="text" NAME="mailtoperson" onChange="msg(this.form)"  /> 
    			</h2>
               
                                                                       
                   					   
                                      <INPUT TYPE="hidden" SIZE=45 NAME="Enter Quiz Title Here" onChange="msg(this.form)" />
                                       
                                      <INPUT TYPE="hidden" SIZE=45 NAME="subject" value="Enter Quiz Title Here - hidden" onChange="msg(this.form)" />  </div>
                                      
                                
           
    
       
    
        <!-- QUIZ MAIN -->
    
      <!-- QUIZ TOP QUESTIONS -->
      
      
                <div id="step-1" >   
    
                	<h2 >Question 1</h2>
               
              				 <p class="question" >    
                  				  1- At what redemption amount do we require authorization  from head office? Where at  head office would you send a request to obtain their authorization?                   		  </p>
               
                       
                          <span class="question">
                             
                             <textarea name="1" id="styled" cols="80" rows="5" onChange="msg(this.form)" ></textarea>
                        
    
                         </span>       		 </div>
    
                <div id="step-2">
              
                <h2 >Question 2</h2>   
    
                            
                      	 <p class="question">    
                  				 
                                  2- At what redemption amount do we require authorization  from head office? Where at  head office would you send a request to obtain their authorization?                    		  </p>
               
                       
                          <span class="question">
                             
                             <textarea name="2" id="styled" cols="80" rows="5"  onChange="msg(this.form)" ></textarea>
                         </span>        </div>                      
    
                <div id="step-3">
    
                <h2 >Question 3</h2>   
    
    				 <p class="question">    
                  				 
                                  3- At what redemption amount do we require authorization  from head office? Where at  head office would you send a request to obtain their authorization?                    		  </p>
               
                       
                          <span class="question">
                              
                             <textarea name="3" id="3" cols="80" rows="5" onChange="msg(this.form)"></textarea>
                         </span>        </div>
    
                <div id="step-4">
    
                <h2 >Question 4</h2>   
    
                     <p class="question">    
                                                 
                                                  4- At what redemption amount do we require authorization  from head office? Where at  head office would you send a request to obtain their authorization?                                          </p>
                               
                                       
                                          <span class="question" >
                                              
                                             <textarea name="4" id="4" cols="80" rows="5" onChange="msg(this.form)"></textarea>
                                         </span>        </div>
            
            <div id="step-5" >
    
                <h2 >Question 5</h2>   
    
             <p class="question">    
                  				 
                                  5- At what redemption amount do we require authorization  from IPC head office? Where at IPC head  office would you send a request to obtain their authorization?                   		  </p>
               
                       
                          <span class="question">
                               
                             <textarea name="5" id="5" cols="80" rows="5" onChange="msg(this.form)"></textarea>
                         </span>        </div>
            
            <div id="step-6">
    
                <h2 >Question 6</h2>   
    
               <p class="question">    
                  				 
                                  6- At what redemption amount do we require authorization  from head office? Where at  head office would you send a request to obtain their authorization?                    		  </p>
               
                       
                          <span class="question">
                              
                             <textarea name="6" id="6" cols="80" rows="5" onChange="msg(this.form)"></textarea>
                         </span>        </div>
            <div id="step-7">
    
                <h2 >Question 7</h2>   
    
                 <p class="question">    
                  				 
                                  7- At what redemption amount do we require authorization  from head office? Where at  head office would you send a request to obtain their authorization?                    		  </p>
               
                       
                          <span class="question">
                              
                             <textarea name="7" id="7" cols="80" rows="5"  onChange="msg(this.form)"></textarea>
                         </span>        </div>
            
            <div id="step-8">
    
                <h2 >Question 8</h2>   
    
                 <p class="question">    
                  				 
                                  8- At what redemption amount do we require authorization  from head office? Where at  head office would you send a request to obtain their authorization?                    		  </p>
               
                       
                          <span class="question">
                              
                             <textarea name="8" id="8" cols="80" rows="5" onChange="msg(this.form)"></textarea>
                         </span>        </div>
            
            <div id="step-9">
    
                <h2 >Question 9 </h2>   
    
                 <p class="question">    
                  				 
                                  9- At what redemption amount do we require authorization  from head office? Where at  head office would you send a request to obtain their authorization?                    		  </p>
               
                       
                          <span class="question">
                              
                             <textarea name="9" id="9" cols="80" rows="5"  onChange="msg(this.form)"></textarea>
                         </span>        </div>
            
            <div id="step-10">
    
                <h2 >Question 10</h2>   
    
     <p class="question">    
                  				 
                                  10- At what redemption amount do we require authorization  from head office? Where at  head office would you send a request to obtain their authorization?                    		  </p>
               
                       
                          <span class="question">
                              
                             <textarea name="10" id="10" cols="80" rows="5" onChange="msg(this.form)"></textarea>
                         </span>   
              
            </div>
    
                  <!-- END QUIZ QUESTIONS --> 
            </div>
            
            
            <!-- End Form -->  
                    
                    
          </form>
    
       
    
      <script type="text/javascript">  
                    function msg() {
                    document.mailer.action = "mailto:" 
                    mailtoandsubject = ( ( document.mailer.mailtoperson.value) + '?subject=' + document.mailer.subject.value ); 
    				
                    } 
    				
              </script>
    My intranet server does not support ASP or PHP, and I do not know JSP, so I am stuck with this for now.

    Would much appreciate any help you can give.
    Last edited by VIPStephan; 08-23-2013 at 01:33 PM. Reason: corrected code BB tags

  • #2
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    A friend suggested I try this - but could not get it to work.

    function append(form)

    {

    // loop through form elements
    for(var i=0;i<form.elements.length;i++)

    {

    // append carriage returns

    form.elements[i].value = form.elements[i].value + ‘%0A’;

    }

    }

  • #3
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Would an onBlur event help?

    I am not sure how to code it but adding an onBlur that would add '\r\r' would probably give me what I am looking for.

    Can anybody help with that code?

  • #4
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,276
    Thanks
    28
    Thanked 272 Times in 266 Posts
    Quote Originally Posted by premium copy View Post
    Before I begin I know - bad idea - but this is for work and will be used on our intranet in a closed environment where everyone is using IE7 and Outlook.
    Internet Explorer 7? Are you using Windows 2000?

    Quote Originally Posted by premium copy View Post
    Problem:
    The plain/text output to the email does not have spaces or carriage returns between the answers. So the answers sometimes look like a big block of characters.q
    I pasted your code into a text editor without further modification and Firefox 23/Thunderbird 17 show the text fine, so apparently this is an IE7/Outlook problem.

    I'd imagine you're going to have a hard time finding someone to set up a live email address on Outlook to troubleshoot IE7. I tried testing this code on a Windows XP IE8 image, but apparently I can't test Outlook without configuring it using a live email address, which I'm not willing to do. (I don't even bother to download IE7 images because that browser is so old.)

    Quote Originally Posted by premium copy View Post
    A friend suggested I try this - but could not get it to work.

    function append(form)

    {

    // loop through form elements
    for(var i=0;i<form.elements.length;i++)

    {

    // append carriage returns

    form.elements[i].value = form.elements[i].value + %0A;

    }

    }
    The correct way to escape characters in JavaScript is using \x## or \u#### where ## and #### represent two- and four-digit Unicode code-points. U+000A LINE FEED would therefore be represented via \x0a or \u000a. However, in JavaScript, there's a shortcut for that character: \n (for "new line").

    In Windows, new lines are represented by a CARRIAGE RETURN character followed by a LINE FEED character, so you'd use \r\n for a new line.

    No idea if these changes will fix your issue though. Adding new lines to the end of every textarea element via script had no effect when I tried it using Firefox/Thunderbird.
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #5
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    It actually appears to be ie8 running in ie7 compatability mode. They are testing ie10 but I assume all of our webapps are delaying the process.

    Anyway, thanks for the response.

    I did get the following JQuery code to work as an onBlur event but I am not sure how to set it up as an onSubmit event. The onBlur was adding the spaces before the typing instead of after, so I think the onSubmit would work correctly.

    Code:
    $('textarea').each(function(){ $(this).val( $(this).val() + '\n\n'  ); });

  • #6
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Sorry, not onBlur. This is applied to all textareas.

    Code:
    <script>
    $('textarea').each(function(){ $(this).val( $(this).val() + '\n\n'  ); });  
    </script>

  • #7
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    Code:
    <script>
    $("#frm").submit(function(){
    $(this).find("textarea").each(function(){ $(this).val( $(this).val() + '\n\n'  ); });  
    })
    </script>
    Last edited by DanInMa; 08-26-2013 at 03:02 PM. Reason: fixed

  • Users who have thanked DanInMa for this post:

    premium copy (08-26-2013)

  • #8
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DanInMa View Post
    Code:
    <script>
    $('#frm").submit(function(){
    $(this).find("textarea").each(function(){ $(this).val( $(this).val() + '\n\n'  ); });  
    })
    </script>
    PERFECT! Thanks for the help.

    Minor correction with the '#frm" to '#frm' but all good!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •