Got more questions? Find advice on: SQL | XML | Regular Expressions | Windows
Welcome to AspAdvice Sign in | Join | Help

A couple of questions about inserting Javascript into an .aspx page...

  •  02-04-2007, 12:00 AM

    A couple of questions about inserting Javascript into an .aspx page...

    Hello,

    I'm a newbie to ASP.NET who is trying to insert a  rough-and-ready email form into an .aspx page. I have inserted a javascript (pasted at end of this message) intended to collect form info and fire an email upon submit. However, when running the page I get a  "Object reference not set to an instance of an object" error. Will the Javascript only work in a regular .html page, or can ASP.NET controls and Javascript play well together?

    Also, when I test the form (in a seperate .HTM page), all of the results of the form get written to the email in one ugly, unbroken line, i.e.:

    Name isBob SmithEmail isbobsmith@yahoo.comPhone is555-555-5555Fax is555-555-4567Message: test message

    I'm using Mozilla Thunderbird, and testing the emails fired by the Javascript to my own address. Is there some way to format the javascript so that the emails sent by it will be formatted in a nice way, with carriage returns? i.e.:

    Name is Bob Smith
    Email is bobsmith@yahoo.com
    Phone is 555-555-5555
    Fax is 555-555-4567
    Message: test message

    Any help or advice would be greatly appreciated. The script is as follows (I have cut some fields out for brevity):

    Header:
            <script name="JavaScript">
                        <!-- Copyright 2000 by William Bontrager
                        function SendEmail()
                        {
                     var toaddy = 'email@email.net';
                     var subject = 'ATTN: Request Information';
                     var mailer = 'mailto:' + toaddy + '?subject=' + subject + '&body=' +
                        'Name%20is\n\t' + document.jsform.visitorname.value +
                            '\n\n' +
                        'Email%20is\n\t' + document.jsform.email.value +
                            '\n\n' +
                        'Message:\n\n' + document.jsform.message.value +
                            '\n\n';
                            parent.location = mailer;
                         } // -->
                </script>

    Body:
            <form name="jsform">
                             <table><tr>
                                  <td align="right">Name</td>
                                  <td><input name="visitorname" size="27"></td>
                                  </tr><tr>
                                  <td align="right">E-mail</td>
                                  <td><input name="email" size="27"></td>
                                  </tr><tr>
                      <td colspan="2">
                                     Your message:<br>
                                     <textarea name="message" cols="31" rows="10" wrap="soft">
                                       </textarea>
                                      <center>
                                      <p>
                                  <input type="submit" onClick="SendEmail()" value="Send Message">
                                      </center>
                                   </td>
                                 </tr></table>
                              </form>

     

     Thanks again!

     

    Filed under: , , ,
View Complete Thread