I have many checkbox that comes from database and then using foreach loop. i put if else in my foreach loop to set if the user already select the 3rd checkbox then all other checkbox will reject the user selection like uncheck automatically or disabled. I want to make it disabled but if i do that all checkbox will be disabled. If you see the where i use if else condition for $countses, then there is where i want to use the code. but i don't how to make it uncheck automatically once the user has select the 3rd checkbox.
NOTE:i can disabled it by PHP.but it needs to be refreshed first rather than implement it directly. so i guess i need help in javascript
My code looks like this
$query="SELECT abc.*
FROM (".$selector.")abc
WHERE
abc.studentname LIKE :q OR
abc.matricno LIKE :q OR
abc.title LIKE :q OR
abc.year LIKE :q OR
abc.thesis_level LIKE :q OR
abc.programme LIKE :q OR
abc.serialno LIKE :q
LIMIT ".$startrow.",".$limitrow;
$stmt = $db->prepare($query);
$stmt->bindValue(':q','%'.$q.'%');
$stmt->bindValue(':e',$e);
$stmt->execute();
$startPage = ($pageno <5) ? 1 : $pageno -4;
$endPage = 8 + $startPage;
$endPage = ($maxpage < $endPage) ? $maxpage : $endPage;
$diff = $startPage - $endPage + 8;
$startPage -=($startPage - $diff > 0) ? $diff : 0;
$a = $startPage;
echo "<ol id='olpoint'>";
if($startPage > 1) echo "<a href='#' onclick='ajaxSearchUpdater(1);'><li>First</li></a>";
while($a<=$endPage){
echo "<a href='#' onclick='ajaxSearchUpdater(".$a.");' style='text-decoration:none;'><li ";
if($pageno == $a){
echo "style='color:grey;font-size:medium;'";
}
echo ">".$a."</li></a>";
$a++;
};
if($endPage < $maxpage) echo "<a href='#' onclick='ajaxSearchUpdater(".$maxpage.");'><li>End</li></a>";
echo "</ol>";
if($stmt->rowCount() > 0){
$r=$stmt->fetchAll();
echo "<table class='tablesorter-blackice' id='myTable' style='width:97%; table-border: 1'>";
echo "<thead>";
echo "<tr>";
echo "<th>No.</th>";
echo "<th>No.Matric</th>";
echo "<th>Name</th>";
echo "<th>Programme</th>";
echo "<th>Title</th>";
echo "<th>Thesis Level</th>";
echo "<th>Serial Number</th>";
echo "<th>Availability</th>";
echo "<th>Select book (Max 3)</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
if(isset($_SESSION['sBorrow']))
$arraynosiri = $_SESSION['sBorrow'];
else
$arraynosiri = array();
$countses = count($_SESSION['sBorrow']);
foreach($r as $row){
echo "<tr align='center'><td>". ($startrow+1) ."</td><td>". $row['matricno'] ."</td><td>". $row['studentname'] ."</td><td>". $row['programme'] ."</td><td>". $row['title'] ."</td><td>". $row['thesis_level'] ."</td><td>". $row['serialno'] ."</td><td>". $row['bavailable'] ."</td><td>
<form method='post'>";
if($key = array_search($row['serialno'], $arraynosiri) !== false) {
$checkbox = "checked";
}
else{
$checkbox = "";
}
if($countses > 3){
echo "MAX";
}
else{
echo "MIN";
}
if($row['bavailable'] == "Available"){
echo "<input type='checkbox' name='sBorrow' id='sBorrow' class='sBorrow' value='". $row['serialno'] ."' ".$checkbox.">
</form></td></tr>";
}
else{
echo "<input type='checkbox' name='sBorrow' id='sBorrow' class='sBorrow' value='". $row['serialno'] ."' ".$checkbox." style='color: grey;' disabled>
</form></td></tr>";
}
$startrow++;
//echo $row['education_level'];
}
echo "</tbody>";
echo "</table>";
}
else{
echo "<p align='center' style='color:white'; class='reminder'>Nothing to show you :( I am really sorry for this T_T </p>";
}
Aucun commentaire:
Enregistrer un commentaire