views:

8

answers:

0

I have one critical issue .I have a dropdown list and a list.within that list I have many checkboxes for property size.Now I want to validate in such a way that, if I select apparel item in dropdown list then list containing the checkboxes should be visible .so user has to select select(checked) one checkboxes.If he select Non-apparel item in dropdownlist,then list should not be visible.At that time user need not to select any checkboxes.that means the checkboxes within the list container has to validated when list is visible.my javascript is as follows,

$(document).ready(function() { $("#ProductType").change(function() { if ($(this).val() == "Apparel") $("#apparelSizes").css("display","block"); else $("#apparelSizes").css("display", "none"); }); });

$(document).ready(function() { jQuery.validator.addMethod("apparelSizeSelected", function(value) { if (jQuery("input:checked").length > 0) return true; else { return false; } }, 'Please select any one apparel size'); $("#form1").validate({

        rules: {
            ProductType: { required: true },
            XS: { apparelSizeSelected: "#apparelSizes:visible" },
            S: { apparelSizeSelected: "#apparelSizes:visible" },
            M: { apparelSizeSelected: "#apparelSizes:visible" },
            X: { apparelSizeSelected: "#apparelSizes:visible" },
            L: { apparelSizeSelected: "#apparelSizes:visible" },
            XL: { apparelSizeSelected: "#apparelSizes:visible" },
            XXL: { apparelSizeSelected: "#apparelSizes:visible" },
            XXXL: { apparelSizeSelected: "#apparelSizes:visible" },
            LargeImageURL: { required: true }

        },

messages: { ProductType: "Product Type is required", XS: "Please select any one apparel size", S: "", M: "", X: "", L: "", XL: "", XXL: "", XXXL: "", } } }); });

displaying of list is working properly based on the requirement.But my problem is checkboxes are validated when list is not visible.please go through the javascript coding what I have given.

I hope the problem is with the custom validation "apparelsizesSelected" what I have written above.please give me solution.