mercredi 28 janvier 2015

create table of checkboxes with select all option

I am creating a table of checkboxes, where the first column will contain checkboxes that can check / uncheck the current row.


This is my code so far, which is not working.



<!DOCTYPE html>
<html>
<head>

<script language="JavaScript">
function toggle(source, $id) {
checkboxes = document.getElementsByName($id);
for (var i = 0, n = checkboxes.length; i < n; i++) {
checkboxes[i].checked = source.checked;
}
}
</script>

</head>

<body>

<?php
echo "<table>";
for ($x = 0; $x < 3; $x++) {
$id = $x;
echo "
<tr>";
echo "
<td>";
echo '<input type="checkbox" onClick="toggle(this, $id)"/> Toggle All';
echo '
</td>
';
for ($y = 0; $y < 7; $y++){
echo "
<td>";
echo '<input type="checkbox" name=$id value="bar1"> Bar 1<br/>';
echo '
</td>
';
}
echo "
</tr>
";
}
echo "</table>";
?>

</body>
</html>


I am aware that the code might contain several errors and am trying to find them. In the meantime, i would appreciate any suggestions.





Aucun commentaire:

Enregistrer un commentaire