关于复选框值的javascript警报

I have checkboxes whose value attribute is coming from database.I want the user to always check the checkboxes having same value if he does not then alert using javascript.I tried to do this using the following javascript code but no use

<script>
    function ck()
    {
        var x,item,f;
        list=document.getElementById("yo");
        f=list[0].value;
        for(index=1;index<list.length;++index)
        {
            item=list[index];
            x=item.value;
            if(x!=f)
            {
                alert("Wrong type checkboxes selected!");
                break;
            }
        }
    }
</script>

Below is the PHP code for checkbboxes

<?php 
    $flag1=-1;
    $conn = mysqli_connect("localhost", "root","","discvr");
    if(! $conn )
    {
        die('Could not connect: ' . mysql_error());
    }

    for($i = 0; $i < 150; $i++) {
        echo "<tr>";
        $cur_date=date("Y-m-d");
        echo "<td>Noida Sector ".($i+1)."</td>";
        $location="Noida Sector ".($i+1);
        for($j=1;$j<=8;$j++)
        {
            $time_id=$j;
            $sql="select status from final where location = '$location' AND date='".$cur_date."' AND time_id=$time_id";
            $query=mysqli_query($conn,$sql);
            if(!$query)
            {
                $status=0;
                echo "Hi";
            }
            else
            {
                if($row=mysqli_fetch_array($query))
                {   
                    //echo "hi";
                    $status=$row['status'];
                }
                else
                    $status=0;
                //echo $time_id;
            }
            if($i==0)
                echo "<td><input type='checkbox' id='yo' name=time[] value=".$j." value='".$status."' onclick='ck()' > $status </td>";
            else
                echo "<td><input type='checkbox' id='yo' name=time".$i."[] value=".$j."  value='".$status."' onclick='ck()' >$status</td>";
        }

        echo "</tr>";
    }
?>

give unique id's to each checkbox even you are not using them.

Note: on your page id's should be unique.

try like this:

use your connection and other this ,it is for demo.

<?php 


    for($i = 0; $i < 150; $i++) {
        echo "<tr>";
        $cur_date=date("Y-m-d");
        echo "<td>Noida Sector ".($i+1)."</td>";
        $location="Noida Sector ".($i+1);
        for($j=1;$j<=8;$j++)
        {

            if($i==0)
                echo "<td><input type='checkbox' id='yo$i' name=time[] value=".$j." value='".$status."' onclick='ck(this.value)' > $status </td>";
            else
                echo "<td><input type='checkbox' id='yo$i' name=time".$i."[] value=".$j."  value='".$status."' onclick='ck(this.value)' >$status</td>";
        }

        echo "</tr>";
    }
?>

javascript:

<script>
    function ck(value)
    {
        var x,item,f;
       list= document.getElementsByTagName("input");
        f=value;
        console.log(f);
        for(i=1;i<list.length;++i)//change your logic here don't know what you are trying here
        {
            item=list[i];
            x=item.value;
            if(x!=f)
            {
                alert("Wrong type checkboxes selected!");
                break;
            }
        }
    }
</script>