Problem with setting an onsubmit event
I have a page with several different forms. One of these currently has an onsubmit event to run a custom validation program before the action is triggered. This event is currently shown as
- onsubmit="return validateForm(this)"
and works as expected.
I want to be able to use this form in some instances without this validation so I want to take this event out and add it if a certain field has been set before the page was loaded. I'm new to jQuery and thought I'd understood how I could do this but I'm not getting this to work.
First of all I added a class of 'mainform' to this form and then used the following to set the event:
- $(document).ready(function() {
- $('.mainform').onsubmit = function (event) {
- return validateForm(this);
- };
- })
I've tried putting line 4 in quotes but it still doesn't work. What am I doing wrong?
Thanks
Eric.