Loop table data in JavaScript
  • I have this  working javascript code 
     $("tr[data-id=1]").find("input[id='1_Satisfactory']").click(function () {
                if ($(this).is(":checked")) {
                // alert('checked');
                $("tr[data-id=1]").find("input[id='1_Feasible']").attr('checked', false);
                $("tr[data-id=1]").find("input[id='1_Implemented']").attr('checked', false);
                }
                });
                $("tr[data-id=1]").find("input[id='1_Implemented']").click(function () {
                if ($(this).is(":checked")) {
                // alert('checked');
                $("tr[data-id=1]").find("input[id='1_Feasible']").attr('checked', false);
                $("tr[data-id=1]").find("input[id='1_Satisfactory']").attr('checked', false);
                }
                });
                $("tr[data-id=1]").find("input[id='1_Feasible']").click(function () {
                if ($(this).is(":checked")) {
                // alert('checked');
                $("tr[data-id=1]").find("input[id='1_Satisfactory']").attr('checked', false);
                $("tr[data-id=1]").find("input[id='1_Implemented']").attr('checked', false);
                }
                });
               
                $("tr[data-id=2]").find("input[id='2_Satisfactory']").click(function () {
                if ($(this).is(":checked")) {
                // alert('checked');
                $("tr[data-id=2]").find("input[id='2_Feasible']").attr('checked', false);
                $("tr[data-id=2]").find("input[id='2_Implemented']").attr('checked', false);
                }
                });
                $("tr[data-id=2]").find("input[id='2_Implemented']").click(function () {
                if ($(this).is(":checked")) {
                // alert('checked');
                $("tr[data-id=2]").find("input[id='2_Feasible']").attr('checked', false);
                $("tr[data-id=2]").find("input[id='2_Satisfactory']").attr('checked', false);
                }
                });
                $("tr[data-id=2]").find("input[id='2_Feasible']").click(function () {
                if ($(this).is(":checked")) {
                // alert('checked');
                $("tr[data-id=2]").find("input[id='2_Satisfactory']").attr('checked', false);
                $("tr[data-id=2]").find("input[id='2_Implemented']").attr('checked', false);
                }
                });
    And i want to use loop to simply it.I came up with this but it is not working:

      for (var i = 1; i <= 2; ) 
                {
                    $("tr[data-id=" + i + "]").find("input[id='" + i.toString().concat("_Satisfactory']")).click(function () {
                        if ($(this).is(":checked")) {
                            // alert('checked');
                            $("tr[data-id=" + i + "]").find("input[id='" + i.toString().concat("_Feasible']")).attr('checked'false);
                            $("tr[data-id=" + i + "]").find("input[id='" + i.toString().concat("_Implemented']")).attr('checked'false);
                        }
                    });
                    $("tr[data-id=" + i + "]").find("input[id='" + i.toString().concat("_Implemented']")).click(function () {
                        if ($(this).is(":checked")) {
                            // alert('checked');
                            $("tr[data-id=" + i + "]").find("input[id='" + i.toString().concat("_Feasible']")).attr('checked'false);
                            $("tr[data-id=" + i + "]").find("input[id='" + i.toString().concat("_Satisfactory']")).attr('checked'false);
                        }
                    });
                    $("tr[data-id=" + i + "]").find("input[id='" + i.toString().concat("_Feasible']")).click(function () {
                        if ($(this).is(":checked")) {
                            // alert('checked');
                            $("tr[data-id=" + i + "]").find("input[id='" + i.toString().concat("_Satisfactory']")).attr('checked'false);
                            $("tr[data-id=" + i + "]").find("input[id='" + i.toString().concat("_Implemented']")).attr('checked'false);
                        }
                    });
                    i++;
                }
    Why this script is not working?
    Thank You

  • 2 Comments sorted by
  • This code solved the problem:
      //equipment supply
                var ids = [1, 2, 3, 4, 5, 6, 7, 8];
                $.each(ids, function(indx, i) {
                    //console.debug("inside col1:"+i);
                    $("tr[equipsupply-data-id=" + i + "]").find("input[id='" + i + "_Satisfactory']").click(function() {
                       // console.debug("inside " + i);
                        if ($(this).is(":checked")) {
                            $("tr[equipsupply-data-id=" + i + "]").find("input[id='" + i + "_Feasible']").attr('checked'false);
                            $("tr[equipsupply-data-id=" + i + "]").find("input[id='" + i + "_Implemented']").attr('checked'false);
                        }
                    });
                    $("tr[equipsupply-data-id=" + i + "]").find("input[id='" + i + "_Implemented']").click(function () {
                       // console.debug("inside col2:" + i);
                        if ($(this).is(":checked")) {
                            $("tr[equipsupply-data-id=" + i + "]").find("input[id='" + i + "_Feasible']").attr('checked'false);
                            $("tr[equipsupply-data-id=" + i + "]").find("input[id='" + i + "_Satisfactory']").attr('checked'false);
                        }
                    });
                    $("tr[equipsupply-data-id=" + i + "]").find("input[id='" + i + "_Feasible']").click(function() {
                       // console.debug("inside col3:" + i);
                        if ($(this).is(":checked")) {
                            $("tr[equipsupply-data-id=" + i + "]").find("input[id='" + i + "_Satisfactory']").attr('checked'false);
                            $("tr[equipsupply-data-id=" + i + "]").find("input[id='" + i + "_Implemented']").attr('checked'false);
                        }
                    });
                });

  • thanks for share with others. can you please explain what mistake you was doing ?

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Tagged

Popular Posts of the Week

Top Posters Weekly

Optimum Creative