Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 4th, 2007, 12:45 AM
Authorized User
Join Date: Oct 2006
Posts: 42
Thanks: 3
Thanked 0 Times in 0 Posts
Default Running a Javascript form in ASP.NET:problem


I'm a stupid newbie trying to insert a quick-and-dirty Javascript email form in an .aspx page. For some reason, trying to execute the form returns 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?

Any help or advice would be much appreciated. For reference, the javascript inserted is:

script name="JavaScript">
                    <!-- Copyright 2000 by William Bontrager
                    function SendEmail()
                        var toaddy = '[email protected]';
                        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 +
                        parent.location = mailer;
                     } // -->

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

Old February 4th, 2007, 05:45 AM
Imar's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

Hi there,

I am not sure what you're trying to do, but there are a few problems with your code. First, look at this:

<form name="jsform">

If you look in the HTML in the browser, there's a fair chance that ASP.NET renamed your form to something else. By default, you only have one form, and .NET takes care if it. The final HTML in the browser may shed some light on this.

Second, your form elements may have been renamed, so visitorname is no longer visitorname. Again, look in the HTML for this.

Then the onsubmit. Your function is fired, but the form is also submitted to te server. Not sure if that's what you find.

Finally, look at this:

 parent.location = mailer;

Are you working with frames??

If you explain what your code is supposed to do, I may be able to help you with a .NET alternative....

Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Old February 5th, 2007, 09:01 PM
Authorized User
Join Date: Jul 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts

I personally haven't had much experience using javascript to send an email so obviously I'm biased but I would perhaps suggest using VB or C# to send your email. There are lots of examples out there on how to do it. Plus Imar is correct. Lots of things get renamed so doing it with the .NET framework will help you get around some of your issues. Just a suggestion. - Jason

Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript problem in asp.net sen321x .NET Framework 2.0 1 October 31st, 2007 09:33 PM
Error while running javascript code in ASP.NET Pag fozia_izhar ASP.NET 1.0 and 1.1 Professional 2 December 20th, 2006 03:39 AM
ASP.NET Running and Installation Problem param99 ASP.NET 1.0 and 1.1 Professional 1 November 6th, 2006 03:04 AM
Problem in running ASP.Net 2.0 exstream ASP.NET 2.0 Professional 0 April 26th, 2006 08:48 AM
Problem running app with ASP.NET akhilvira ASP.NET 1.0 and 1.1 Basics 1 January 14th, 2005 09:53 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.