title: PHP, JAVASCRIPT inside php loop
body: <p>I currently working with voting system. Everytime a voter selects a candidate the javascript should work but nothing happens. Here is my code.</p>
  
  <pre><code>&lt;?php while ($row = $stmt-&gt;fetch()) { ?&gt;    
      &lt;div class="form-group"&gt;
          &lt;div class="row"&gt;
              &lt;label class="control-label col-md-3 col-md-push-1" id="labelpad" for="username"&gt;&lt;?php echo $row['position']; ?&gt;&lt;/label&gt;
                  &lt;div class="col-md-6 col-md-push-0"&gt;&lt;br&gt;
                      &lt;?php 
                      $stmt1 = $con-&gt;prepare("SELECT * FROM candidate WHERE position = ?");
                      $stmt1-&gt;bindParam(1, $row['position']);
                      $stmt1-&gt;execute();
                      while ($row1 = $stmt1-&gt;fetch()) 
                      {                   
                      ?&gt;
                      &lt;label&gt;
                          &lt;input id="" class="uniform_on" name="selector[]" type="checkbox" value="&lt;?php echo $row1['candidate_id'];?&gt;"&gt;
                      &lt;/label&gt;
                      &lt;?php echo "&lt;label&gt;".$row1['name']."&lt;/label&gt;"; ?&gt;&lt;br&gt;
                              &lt;script&gt;        
                                  $(".uniform_on").change(function(){
                                  var max= &lt;?php $row1['vote_limit'];?&gt;
                                  if( $(".uniform_on:checked").length == max {
                                      $(".uniform_on").attr('disabled', 'disabled');
                                          alert('5 Items allowed per borrow');
  
                                      $(".uniform_on:checked").removeAttr('disabled');
  
                                  }else{
  
                                      $(".uniform_on").removeAttr('disabled');
                                  }
                                  })
                              &lt;/script&gt;
                      &lt;?php } ?&gt;
                  &lt;/div&gt;  
              &lt;/div&gt;
  </code></pre>