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"%>'
                        }
        );

});

Reply via email to