Showing posts with label Multiple Textbox. Show all posts
Showing posts with label Multiple Textbox. Show all posts

Thursday, January 8, 2015

How to check if multiple textbox have same value?

//First get the counting of textbox
             flag = false;
             cnt =0
            $(".dyntxt").each(function () {
                if ($(this).val() == "") {
                    flag = true;
                    $(this).focus();
                    return false;
                }
            cnt =cnt +1
            });
//To Check Textbox is fiiled or not
            if (flag) {
                alert("Please fill student name")
                return false;
            }
            else if (!flag) {
                count = Number(cnt - 1);
               //count = Number((document.frmDefineSSS.cboTeamSize.selectedIndex) - 1);
                flagSame = false;
//to check the duplicate value
                for (i = 1; i <= count; i++) {
                    for (j = i + 1; j <= count + 1; j++) {

                        if ($("#txtStudName" + [i]).val() == $("#txtStudName" + [j]).val()) {
                            alert("Team Member can't be same.");
                            $("#txtStudName" + [i]).css("background-color", "yellow");
                            $("#txtStudName" + [j]).css("background-color", "yellow");
                            flagSame = false;
                            return false;

                        }
                        else {
                            $("#txtStudName" + [i]).css("background-color", "white");
                            $("#txtStudName" + [j]).css("background-color", "white");
                            flagSame = true;
                        }
                    }
                }
            }
            if(flagSame) {
                document.frm.action = ""
                document.frm.submit()
                return true
            }