title: javascript alert on checkbox value
body: <p>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</p>
  
  <pre><code>&lt;script&gt;
      function ck()
      {
          var x,item,f;
          list=document.getElementById("yo");
          f=list[0].value;
          for(index=1;index&lt;list.length;++index)
          {
              item=list[index];
              x=item.value;
              if(x!=f)
              {
                  alert("Wrong type checkboxes selected!");
                  break;
              }
          }
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>Below is the PHP code for checkbboxes</p>
  
  <pre><code>&lt;?php 
      $flag1=-1;
      $conn = mysqli_connect("localhost", "root","","discvr");
      if(! $conn )
      {
          die('Could not connect: ' . mysql_error());
      }
  
      for($i = 0; $i &lt; 150; $i++) {
          echo "&lt;tr&gt;";
          $cur_date=date("Y-m-d");
          echo "&lt;td&gt;Noida Sector ".($i+1)."&lt;/td&gt;";
          $location="Noida Sector ".($i+1);
          for($j=1;$j&lt;=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 "&lt;td&gt;&lt;input type='checkbox' id='yo' name=time[] value=".$j." value='".$status."' onclick='ck()' &gt; $status &lt;/td&gt;";
              else
                  echo "&lt;td&gt;&lt;input type='checkbox' id='yo' name=time".$i."[] value=".$j."  value='".$status."' onclick='ck()' &gt;$status&lt;/td&gt;";
          }
  
          echo "&lt;/tr&gt;";
      }
  ?&gt;
  </code></pre>