I have this scrip, and i want to check only two checkbox. But not working, and I don't know why.
(Sorry my english, this is not my first languages :( )
This is the php code, with the while loop table creation.
<?php
include "connection.php";
$sql = "SELECT * FROM $tablename";
if($result = mysqli_query($mysqli, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table>";
echo "<tr>";
echo "<th>nev</th>";
echo "<th>hely</th>";
echo "<th>size</th>";
echo "<th>valasztas</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['nev'] . "</td>";
echo "<td>" . $row['hely'] . "</td>";
echo "<td>" . $row['size'] . "</td>";
echo "<td><input type='checkbox' class='single-checkbox' name='checkbox[]' /></td>";
echo "</tr>";
}
echo "</table>";
// Free result set
mysqli_free_result($result);
} else{
echo "No records matching your query were found.";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
mysqli_close($mysqli);
?>
And this is the code whit the jquery script.
<script type="text/javascript">
$(document).ready(function(){
$('.single-checkbox').on('change', function(evt) {
if ($('input[type="checkbox"]:checked').length >= 2) {
this.checked = false;
};
});
});
</script>
Aucun commentaire:
Enregistrer un commentaire