jquery validator - prevent submission on validate?

hi,

I have a form (http://www.regencycollege.co.uk/newsite/index.php?online-enrolment) where I want to validate one part using the jquery validator plugin.

Other parts of the form are populated on the server side and I am using an array to track which parts have been completed before i show the real submit button.

I've tried the following but Ex 1) still gets submitted on validation and Ex 2) gets a this[0] is undefined error.

thanks

anton
Ex 1) 
var form = $("#enrolForm");
	form.validate();
	if (form.valid()){
		result = 1;
	} else {
		result = 0;
	}
...

Ex 2)
$("#enrolForm").validate({
	submitHandler: function(form) {
	  alert('check form');
	}	
});
if ($("#myform").valid()){
	result = 1;
} else {
result = 0;
} 
...

Open in new window

LVL 1
antonumiaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:

Ex 1) 
var form = $("#enrolForm");

        form.validate().form();

        if (form.valid()){
                result = 1;
        } else {
                result = 0;
        }

Open in new window

0
antonumiaAuthor Commented:
hi,
Sadly that still submits the form.
0
hieloCommented:
I tried step 2 again (Your Details) and it does not submit when I clear out the fields. It shows all the error messages. What are you doing?
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

antonumiaAuthor Commented:
ugly but this works.

I'd like to do it inline really.
$(document).ready(function(){
$('#enrolForm').submit(function() {
  return false;
});
});

Open in new window

0
antonumiaAuthor Commented:
I don't want the form to submit when it passes the validation.
I want to submit it elsewhere.
0
hieloCommented:
OK, I thought your issue was that it was not validating and instead it was submitting. On your original post, Ex2.

return false within the submitHandler.
0
antonumiaAuthor Commented:
i was getting a 'this[0] is undefined' when using that.
doesn't matter though as the other fix worked.
0
antonumiaAuthor Commented:
the correct syntax is preventDefault();
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.