Forum Moderators: open

Message Too Old, No Replies

confirmation popup or message after onsubmit

javascript coding

         

Den10

12:14 am on Jul 22, 2008 (gmt 0)

10+ Year Member



Hi Guys, hope someone can help?
I have successfully sent validated form details for the contacts page for a new site that Iam helping with. I have used an external javascript file that checks the inputs (validates) and then once this is ok sends the form using a mailto.
As a tester, I have tried to add extra code under the onsubmit function, just to give an alert to say that the message has been sent (confirmation). I would however prefer some sort of popup window, where i can state that the form has been sent and redirect the user elsewhere etc.this does not seem to be happening at the moment, javascript seems to finish after the action of the onsubmit is complete.
Is there a tag for this action, ie onsuccess etc?
Any ideas? iam open to any suggestions.
ps, iam new to all this, so please be gentle with me, thanks den10

Den10

2:41 pm on Jul 22, 2008 (gmt 0)

10+ Year Member



i have tried to run 2 functions for the onsubmit action, but they end up conflicting, ie, if one runs it disables the error checking that the other did! What i really need is some sort of event related to the form being sent, then i can code this quite easily!
can anyone help, or have experienced similar issues to this?

Fotiman

3:39 pm on Jul 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Here's some pseudo code to get you started...

<form onsubmit="return preProcessForm();">


function preProcessForm() {
var result = true;
result = validate();
if (result) {
// 1. Use AJAX to submit the contents of the form
// 2. Notify the user
alert('Message sent');
// 3. Redirect
}
return false;
}

Den10

3:52 pm on Jul 22, 2008 (gmt 0)

10+ Year Member



unfortunately i have no experience with AJAX,
the problem iam having is that iam calling a function ie,
thisform.onsubmit = function()
{
return validateForm(this);
it will not get to here!
}
iam then adding code under the return, and as it is receiving a true, this is then sending via a mailto , but code underneath seems to be unreachable!
I know thats because its getting a true and exiting
if i add code anywhere else then its running straight off and conflicting with the validate when using another onsubmit....
its a catch 22 as i want it to submit and then to find some sort of event that i can code in to say once sucessful etc.
its as if as soon has the mailto has completed, the java script switches off! which is possibly right, as i can then start the whole process again once an event fires!

any -ideas?

[edited by: Den10 at 4:25 pm (utc) on July 22, 2008]

DrDoc

4:41 pm on Jul 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A
return
will always exit the function and return a value. If you want to perform additional processing, you may need to save the return value and then exit later.

thisform.onsubmit = function() {
var myStatus = validateForm(this);
// do stuff here
return myStatus;
}

Den10

6:48 pm on Jul 22, 2008 (gmt 0)

10+ Year Member



thanks DrDoc, i now have it redirecting and then submitting. Not an ideal set-up, but at least it indicates that the form has been sent and validated, and redirects. gives some sort of indication and moves off the contacts page, to prevent multiple form submissions!
I thank you all for your help!