Re: Problems with onSubmit

by "Rob Parker" <RobParker(at)access.net.au>

 Date:  Thu, 2 Mar 2000 12:17:00 +1100
 To:  <Paul.Anderson(at)atos.co.uk>,
<hwg-style(at)hwg.org>
 References:  ROCHDALEMSG
  todo: View Thread, Original

> I know this isn't stricly speaking a style problem,

Quite so. The techniques list would be a better place to post this query.
Nevertheless, here's a few comments.

>          but has anyone else had
> problems with the onSubmit event handler within the <FORM> tag?
> According to the Developers Guide to JavaScript 1.1 the syntax is:
> <FORM METHOD="POST"  ACTION="/cgi-bin/mailscript" onSubmit="return
> doCheck(this)" where 'doCheck' is the JavaScript function to validate the
> form.
> According to Microsoft's knowledge base the syntax is :
> <form method="POST" action="/cgi-bin/mail" onSubmit="return(docheck());">
> I've tried both, and several variations in between, and nothing seems to
> trigger the JavaScript, it just goes ahead and submits the form.
> Is anyone else having a problem with this, or has anyone got the onSubmit
> handler working and can tell me how?
>

The onSubmit handler works fine, IF you use it as your JavaScript function
and server setup expects.

The general syntax you are using is <FORM METHOD="POST"  ACTION="cgi file
path/name" onSubmit="return JavaScript_functionname()">.  You have quoted
two examples, which are both different. In the first, the cgi program which
will process your form is called "mailscript", and is located in the cgi-bin
directory of your server; in the second, the cgi program is called "mail",
and is (again) located in cgi-bin directory [note: this is a common setup
for cgi programs]. Therefore, the first thing to do is to ensure that the
ACTION attribute of your FORM is pointing at the correct directory and file
that you are using on your server.

Next, the onSubmit handler will submit the form to the cgi program if
"return" is true. This can be set explicitly in the handler call (ie.
onSubmit="true" will always submit the form), or (as in your case) by using
the (boolean) value returned from a JavaScript function. The exact syntax
you need for that depends on the JavaScript function you are using on your
page to perform the validation. In the first example you quote, the function
name is "doCheck", and it requires a parameter to be passed to it (in this
case, a reference to the form from which it is being called); in the second,
the function name is "docheck", and it has a null parameter list. So, the
next thing to do is to ensure that the function call is correct for the
particular JavaScript function you are using on your page.

Once you've got both these right, your form should only submit when it
validates in accordance with your script.

Rob

HWG hwg-style mailing list archives, maintained by Webmasters @ IWA