Re: form submit events
"Adam Griffis" <[email protected]> Thu, 16 Mar 2006 02:26:34 -0000
| Newsgroups | gmane.comp.web.dom.wdf |
|---|---|
| Message-ID | <[email protected]> |
Hello,
I would probably do the following:
Have a javascript variable global to all the functions, perform each
function dependent on that variable, and also submit the form based on
that variable.
In my sample, both func1 and func2 will be performed, but the form
will not be submitted because submitForm is set to false in func2.
So the javascript would look like this:
-------------------------------------
var submitForm = true;
function func1() {
if (submitForm) {
alert('func1');
// If validation fails, set submitForm to false.
//submitForm = false;
}
}
function func2() {
// This never happens if func1 fails
if (submitForm) {
alert('func2');
// We failed, so don't submit
submitForm = false;
}
}
-------------------------------------
The form I'm submitting would look like this:
-------------------------------------
<html>
<head>
<script type="text/javascript" src="func.js"></script>
</head>
<body>
<form action="submit.html" onsubmit="func1();func2();return submitForm;">
<input type="submit" value="Submit" />
</form>
</body>
</html>
-------------------------------------
And here's the page I submitted to:
-------------------------------------
<html>
<head>
<title>Submitted!</title>
</head>
<body>
<h3>Form successfully submitted!</h3>
</body>
</html>
-------------------------------------
--- In [email protected], Anders Nawroth <list@...> wrote:
>
> Hello!
>
> I'm adding two event listeners to the submit event of a form.
> The first event handler performs a validation, the second handles the
> form submission (I need do do some extra stuff before submitting the
form).
>
> My problem:
> I can't find out how the first event handler should do to stop event
> propagation to the second one (in case of failed validation). I've
tried
> to handle capture/bubble phase and so on, but still can't get it right.
>
> Does anyone have a working example of multiple submit event handlers?
> Any special gotchas when doing stopping form submit events?
>
> /AndersN
>
Unsubscribe
[email protected]
List info
http://www.quirksmode.org/dom/list.html
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/wdf-dom/
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/