1

I am appending table rows on the button click event. I need to avoid duplicate values. Is there a way to avoid duplicates?

my JQuery

       $('#Add').click(function () {
           var TName = $('#TournamentName').val();
           var GName = $('#Gname').val();
           var date = $('#Tdate').val();
           var time = $('#Stime').val();
           var Mtype = $('#Match').val();
           var Ground = $('#Ground').val();
           var ClubA = $('#TeamA').val();
           var ClubB = $('#TeamB').val();
           $('#TournamentName').attr('disabled', true);
           var isDup = false;

           $("#fixtab tbody").each(function (i, n) {
               alert(i);
               alert(n);
               if (($("i").find("[name=TName]").val() == Tname) && ($("i").find("[name=date ]").val() == date) && ($("i").find("[name=time ]").val() == time) && ($("i").find("[name=ClubA ]").val() == ClubA) && ($("i").find("[name=ClubB ]").val() == ClubB) && ($("i").find("[name=Ground ]").val() == Ground)) {
                   alert("error");
                   isDup = true;
                   return false;
               }
               else {
                   $('#fixtab tbody').append("<tr><td><center>" + GName + "</center><input type='hidden' name='GName' value='" + GName + "' /></td><td>" + date + "<input type='hidden' name='date' value='" + date + "' /></td><td>" + time + "<input type='hidden' name='time' value='" + time + "' /></td><td>" + ClubA + "<input type='hidden' name='ClubA' value='" + ClubA + "' /></td><td>" + ClubB + "<input type='hidden' name='ClubB' value='" + ClubB + "' /></td><td>" + Ground + "<input type='hidden' name='Ground' value='" + Ground + "' /></td><td>" + Mtype + "<input type='hidden' name='Match' value='" + Mtype + "' /></td><td><input type='button' class='remove' value='remove'/><input type='hidden' name='TName' value='" + TName + "' /></td><tr>");
               }
           });

Like this I will append more than 10 records, so I need to avoid duplication from this records.

1 Answer 1

1

I dont see any easy way except :

  $('#Add').click(function () {
               var TName = $('#TournamentName').val();
               var GName = $('#Gname').val();
               var date = $('#Tdate').val();
               var time = $('#Stime').val();
               var Mtype = $('#Match').val();
               var Ground = $('#Ground').val();
               var ClubA = $('#TeamA').val();
               var ClubB = $('#TeamB').val();

    var isDup=false;

    $("#fixtab tbody tr").each(function (i,n){
      var _n=$(n);
      if (_n.find("[name=TName]").val()==Tname) &&
          _n.find("[name=date ]").val()==date ) &&
          ..
          ..) 
        {
            isDup=true;
            return false;

        }

    });
Sign up to request clarification or add additional context in comments.

3 Comments

Ya i can use your code it showing i value is 0 and n is [object HTMLTableSelection Element] like this. . .
I don't understand your Q.
Now see my question i edited its not working my friend and n means what friend

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.