Hi, Thanks for the help!
I revised my code but still doesn't work. I know there's wrong in my code but I can't figure it out. Here is the revised code. I hope you can help me with this. <script type="text/javascript"> $().ready(function() { var container = $('div.error-container'); // Validate the form when it is submitted $("#frmCompanyGroup").validate({ rules: { GroupName: { required: true, remote: "contents/company_group_validate_name.asp" } }, messages: { GroupName: { required: "Enter a Group Name", remote: jQuery.format("{0} is already in use") } }, errorContainer: container, errorLabelContainer: $("ol", container), wrapper: 'li', meta: "validate" }); $('#btnCancel').click ( function () { location.href = '<%=MAIN_URL & "co-grp"%>' } ); }); </script> <div class="col60"> <form action="<%=MAIN_URL & sPageOption &"&m=add"%>" method="post" id="frmCompanyGroup" class="basic-form"> <input type="hidden" name="CompanyGroupID" value="< %=lCompanyGroupID%>"> <fieldset class="standard-form"> <legend>Details</legend> <table class="form-table"> <tr> <td class="key"><label for="GroupName">Company Group Name:</label></td> <td><input type="text" name="GroupName" id="GroupName" size="50" maxlength="150" value="<%=sGroupName%>" /></ td> </tr> </table> </fieldset> <div class="standard-form-buttons"> <% If sMode = "edit" Or sMode = "add" Then %><input name="Submit" id="Submit" type="submit" value="<%=sButton%>"><% End If %> <input name="btnCancel" id="btnCancel" type="button" value="Cancel"> </div> </form> Thanks, Nimrod On Jun 11, 1:51 am, "Jörn Zaefferer" <[EMAIL PROTECTED]> wrote: > 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"%>' > > } > > ); > > > });