Trying to make run function after form is submitted

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Trying to make run function after form is submitted

Post by Chris Corbyn »

Hi,

Using javascript to validate a form (sent via a mailto action).

my function in brief is structured like this

Code: Select all

//I'm just using PHP tags because I prefer the highlighting

//Validate
function validate() {
    if (someEl.someVal != "Correct value") {
        alert ('You done it wrong!')
        return false //Don't submit
    } else {
        return true //Submit the form
    }
}
and I'm calling it like this:

Code: Select all

<form action="mailto:myemail@somedomain.com" onSubmit="return validate()">
So it checks the form... good good... prompts to use mailto (a windows based feature i assume) and then submits the form.

But I want to be able to change the innerHTML in a DIV on the page to show that the form was submitted successfully once the user has clicked "OK" on the dialog that asks permission to use the mailto function.

Unfortunately... the line
return true
prevent any further output from the function so all I can do is show the output first but it shows as successful submission to the user before they even click ok.

Can I make it wait until the mailto dialog is accepted. If you dont get what I mean about the mailto dialog try using mailto: as the action in a form and you'll see it.

Thanks :-)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

hmm.. maybe set a timeout event?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Considered that but imagine if the user takes say ten seconds to read the prompt and decide to click "Yes" but the timeout is for 8 seconds or whatever.

While they're pondering over it the status would change to "Your overtime has been submitted successfully" - magic ;-)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what about putting the mail processor on the server?
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

...

Post by Calimero »

Why alerting when form already sent ???


Use button - not type="submit" but type="button"

onClick="validation_function";

JavaScript:

<script language="javascript">

function validation_function()
{
// code to validate
// enter your code here and create a validation_variable with ok/wrong value to compare later



if ( validation_variable_ok )
{
document.form_name_enter_here.submit();
}
else
{
alert("get back and do as your told hijacker");
}

}
</script>


Hope this helps.
See ya !
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Ermmm.... dude. I'm wanting some confirmation that form was submitted, not to shout at them for doing it wrong LOL :lol:

Only problem is that when the form validator returns true the user still has to click OK to allow permission for the mailtio function to automatically send an email.... otherwise it isn't submitted.

The problem is that the javascript has done it's job by this point and the form is submitted in it's eyes as the action="" specified has been done.... I need something that checks the email was actually sent.

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'd say using php to do the form processing is the better direction.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Yeah I'd agree but it's for something they use at work and they just want a simple HTML file all user's can store on the local machine, then the email get's sent out to the team leaders for proccessing once a week.

They'll never change it to use PHP - they wouldn't see the point in going to the effort installing it.

I totally agree though :-)
Post Reply