[Javascript] Unobtrusive onsubmit

Philip Thompson philthathril at gmail.com
Thu Feb 19 12:22:07 CST 2009


On Feb 18, 2009, at 1:03 PM, 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

Try using an anonymous:

document.getElementById('testform').onsubmit = function () {
     return TestDataCheck();
};

Or, if you are using a library (this is particularly mootools):

$('testform').addEvent('submit', function () {
     return TestDataCheck();
});

HTH,
~Philip



More information about the Javascript mailing list