[Javascript] Unobtrusive onsubmit
tedd
tedd at sperling.com
Wed Feb 18 14:58:51 CST 2009
At 2:03 PM -0500 2/18/09, Terry Riegel wrote:
>I am working through an unobtrusive bit of javascript and wonder if
>anyone might be able to lend a hand.
>
> <FORM ACTION="../cgi-bin/mycgi.pl" ID="testform" NAME="testform"
>onSubmit="return TestDataCheck()">
>
>I would like to take this onSubmit out of the form declaration and put
>it in an startup function that runs on load.
>
>So I have this...
>document.getElementById('testform').onsubmit=TestDataCheck;
>I am not sure of the syntax that would duplicate the return part of
>the obtrusive JS.
>I have tried this...
>document.getElementById('testform').onsubmit=return TestDataCheck;
>
>How would I get it to invalidate the action of the form and just do
>something else?
>
>Any help will be greatly appreciated.
>
>Terry Riegel
Terry:
Here's an example that works as you want:
http://www.webbytedd.com/ccc/uob-onsubmit-oneform/index.php
The form simply has a name, in this case 'a'. Besides the javascript
being loaded via the head, there is no other javascript within the
page (except the where it shows the code, but that's for demo only).
As is typical, when the pages loads, the javascript is loaded.
However, the js script monitors what the html is doing and when the
user clicks "submit", javascript takes over and asks for both fields
to be filled. BUT please note -- no javascript hooks (i.e., onClick,
onSubmit) appears within the html, thus it is Unobtrusive. Kind on
neat, huh? :-)
HTH's
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
More information about the Javascript
mailing list