Here is a better example to show the difference between input fields of
type "submit" and js script... Normally you would expect on both buttons
the same effect...
<html>
<script>
function doSubmit() {
if(document.forms['theForm'].onsubmit()) {
submit();
}
}
</script>
<body>
<form id="theForm" onsubmit="alert('form
onsubmit');return true;">
<input type="submit" value="submit"
onclick="doSubmit()" />
<input type="button" value="button test js submit"
onclick="doSubmit()">
</form>
</body>
</html>
On Wed, 28 Sep 2005 23:46:51 +0200, Paul Klaer <[EMAIL PROTECTED]> wrote:
Oh, sorry. You're right.
Didn't saw that this script is invoked by a js command submit(). But if
you click on the browser "submit" button you need to be careful, because
the browser executes onsubmit:
<html>
<body>
<form id="theForm" onsubmit="alert('form onsubmit');return
true;">
<input type="submit" value="submit" />
<input type="button" onclick="document.forms['theForm'].submit();"
value="button test js submit">
</form>
</body>
</html>
On Wed, 28 Sep 2005 23:21:09 +0200, Matt Blum <[EMAIL PROTECTED]> wrote:
No, it's not. When you invoke the submit method on a form, its onsubmit
handler is not executed at all. That's the reason this code is
necessary in
the first place.
-Matt
On 9/28/05, Paul Klaer <[EMAIL PROTECTED]> wrote:
Be careful with that script!
Your onsubmit method is executed twice if it will return a value true!
You have to use this code:
if(document.forms['body:theForm'].onsubmit) {
document.forms['body:theForm'].submit();
} else {
document.forms['body:theForm'].submit();
}
otherwise:
if(document.forms['body:theForm'].onsubmit) {
if(document.forms['body:theForm'].onsubmit()) <<<<<<<- onsubmit is
executed here and if it returns true submit
document.forms['body:theForm'].submit(); <<<<<<<-- and onsubmit is
executed here
} else {
document.forms['body:theForm'].submit();
}
On Wed, 28 Sep 2005 03:24:06 +0200, Saul Qunming Yuan
<[EMAIL PROTECTED]>
wrote:
> if(document.forms['body:theForm'].onsubmit) {
> if(document.forms['body:theForm'].onsubmit())
> document.forms['body:theForm'].submit();
> } else {
> document.forms['body:theForm'].submit();
> }