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?
 
antonumiaConnect With a Mentor Author Commented:
the correct syntax is preventDefault();
0
 
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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
All Courses

From novice to tech pro — start learning today.