开发者

Need help with jQuery validation for a select list [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

jQuery custom validation method issue

I have a select list #technology. It's default value is "0" due to back end payment processor. I need a validation rule (using jquery.validate.js) that makes it return false if it's value is "0" but return true for any other value. What I am trying isn't working.

<script type="text/javascript">
    $(document).ready(function() {
        $.validator.addMethod(
            "SelectTechnology",
            function(value, element) {
                //var selectedCountry = $('#Country').val();
                if ($("#singleTech").val() === '0'){
                    return false;
                } else return true;
            },
            "Please Select a Technology"
        );
        var validator = $("#SinglePmnt").validate({
            rules: {
                    technology: {
                 开发者_如何学运维       SelectTechnology: true
                    }
            },
            errorElement: "span",
            errorPlacement: function(error, element) {
                error.appendTo(element.parent("td"));
            }
        });
    });
</script>

It doesn't clear the error if you hit submit with the default value selected then change it. thanks


You should also use value to get the passed value

if (value == '0')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜