Tuesday 3 November 2015

Check Duplicate value in dynamic Text box using jquery

<script type="text/javascript">
        function findDuplicates() {
           
            var isDuplicate = false;
            jQuery("input.access_keys[type=text]").each(function (i,el1) {
           
                var current_val = jQuery(el1).val();
                if (current_val != "") {
                    jQuery("input.access_keys[type=text]").each(function (i,el2) {
                        if (jQuery(el2).val() == current_val && jQuery(el1).attr("name") != jQuery(el2).attr("name")) {
                            isDuplicate = true;
                            jQuery(el2).css("background-color", "yellow");
                            jQuery(el1).css("background-color", "yellow");
                           
                            return;
                        }
                    });
                }
            });

            if (isDuplicate) {
                alert ("Same Accession no can not be issued more than 1 member.");
                jQuery("input.access_keys[type=text]").val('');
                return false;
            } else {
                return true;
            }
        }
    </script>

No comments: