Hi, I've got a table with 3 cols and each cell has a checkbox. I want to have 3 checkboxes above the table that each one checks/unchecks all the checkboxes in the table but ONLY in one col. so if I click checkbox 1 all the checkboxes in col 1 are checked, if I click checkbox 2 all the checkboxes in col 2 are checked, etc..
I found this code that checks all the checkboxes in 1 <form>, using the form's ID attribute.
but my table is in 1 form, I can't separate it into 3 forms and I can't give the checkboxes in the table different ID or NAME...
I tried to give the table's <td> different ID and using it in the JS function instead of the <form>'s ID but it doesn't work...
here's the code-
<script language='JavaScript'>
checked = false;
function checkedAll () {
if (checked == false){checked = true}else{checked = false}
for (var i = 0; i < document.getElementById('myform').elements.length; i++) {
document.getElementById('myform').elements[i].checked = checked;
}
}
</script>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="myform">
Check col1: <input type='checkbox' name='checkall' onclick='checkedAll();'>
<!-- Check col2: <input type='checkbox' name='checkall' onclick='checkedAll();'>
Check col3: <input type='checkbox' name='checkall' onclick='checkedAll();'>-->
<table width=100%>
<tr class=trHead>
<td> 1</td>
<td> 2</td>
<td> 3</td>
</tr>
//start of a loop
<tr>
<td><input type="checkbox" name="checkbox[]" id="checkbox[]" value="dfg"/>dfg</td>
<td><input type="checkbox" name="checkbox[]" id="checkbox[]" value="dfg"/>df</td>
<td><input type="checkbox" name="checkbox[]" id="checkbox[]" value="sd"/>sd</td>
</tr>
//end of a loop
</table>
</form>