Click to See Complete Forum and Search --> : Submit event


kouk
02-12-2003, 08:20 AM
Hello all ! I need to set up a form to collect data from users. When they click on the Send button, I want their info to be mailto (me) and a thank you page be loaded.
I am restricted to Javascript. How can I make the submit button perform these 2 actions ? Or is there another way to proceed ?
Thanks in advance.:confused:

Rick Bull
02-12-2003, 08:48 AM
I would just add a onsumbit event to the form:

<form action="mailto:you@whereever.com"
enctype="text/plain"
onsubmit="document.URL = 'thank_you.htm';"><p>
<label for="name">Name:</label>
<input id="name" name="Name" />
<label for="email">E-mail:</label>
<input id="email" name="email" />
<label for="comments">Comment(s):</label>
<textarea id="comments" name="comments"></textarea>
</p></form>

This way if the user doesn't have JS they will still send the e-mail, just not get the thank you page :)

Charles
02-12-2003, 10:35 AM
That will not work. The onsubmit handler is called immediately before the form is submitted, in this case loading the "thank you" page in the window. At that point the form will no longer exist and will not, therefore, be submitted. A server side form handling script is needed here.

Rick Bull
02-12-2003, 01:47 PM
Oh yeah, how could I forget that?! :o I suppose the other alternative is to use a pop-up - not a very good alternative but if you have no server-side language it will do:


<form action="mailto:you@whereever.com"
enctype="text/plain"
onsubmit="window.open('thank_you.htm');">