Methods that you add via $.validator.addMethod have to run synchronously, so using ajax in there doesn't work.
The remote method implements the necessary synchronization: http://docs.jquery.com/Plugins/Validation/Methods/remote#url An example for the "unique" remote validation is here: http://jquery.bassistance.de/validate/demo/milk/ (included in the download) Jörn On Tue, Jun 10, 2008 at 5:42 PM, Nimrod <[EMAIL PROTECTED]> wrote: > > Hi All, > > I'm just new to jQuery and I would like to ask for your help with my > validation code. My problem in the code below is that it's not > validating the intended field. What I want to do here is to validate > if a user entered a unique name. > > // a custom method for validating the Group Name > $.validator.addMethod("unique", function() { > $.ajax({ > type: "POST", > dataType: "json", > url: "contents/company_group_validate_name.asp", > data: "name="+$("#GroupName").val()+"&id=<%=lCompanyGroupID%>&m=< > %=sMode%>", > success: function(data){ > if (data.name_exists == "True") { > //alert('Existing!'); > return false; > }else{ > //alert('Not Existing!'); > return true; > } > } > }); > }, 'Please enter a unique name!'); > > > $().ready(function() { > var container = $('div.error-container'); > // Validate the form when it is submitted > $("#frmCompanyGroup").validate({ > errorContainer: container, > errorLabelContainer: $("ol", container), > wrapper: 'li', > meta: "validate", > rules: { > GroupName: { > //required:true, > unique:true > } > } > > }); > > $('#btnCancel').click > ( > function () > { > location.href = '<%=MAIN_URL & "co-grp"%>' > } > ); > > }); >