Reputation: 103
How can I put the name of checkbox in correct way then it can run with the javascript
<?php $i=1; ?>
<?php do { $i++; ?>
<tr>
<td><input name="<?php echo 'checkbox[$i]' ; ?> " type="checkbox" id="<?php echo $row_RsActivitynoteMem['id']; ?>" value="<?php echo $row_RsActivitynoteMem['id']; ?>" />
<label for="checkbox"></label></td>
<td><?php echo $row_RsActivitynoteMem['Sname']; ?> <?php echo $row_RsActivitynoteMem['Ssurname']; ?></td>
<td width="20"><?php echo $row_RsActivitynoteMem['idactivity']; ?></td>
<td><?php echo $row_RsActivitynoteMem['kname']; ?></td>
<td> </td>
</tr>
<?php } while ($row_RsActivitynoteMem = mysql_fetch_assoc($RsActivitynoteMem)); ?>
<tr>
<td> </td>
<td> </td>
<td width="20"> </td>
<td> </td>
<td> </td>
</tr>
</table>
<input type="button" name="CheckAll" value="Check All"
onClick="checkAll(document.form1.checkbox)">
<input type="button" name="UnCheckAll" value="Uncheck All"
onClick="uncheckAll(document.form1.checkbox)">
<br>
</form>
</body>
</html>
<?php
mysql_free_result($RsActivitynoteMem);
?>
How can I make CheckAll at the bottom work and handle the check box variable when sending to another page?
This javascript worked:
function checkAll(field)
{
for (i = 0; i < field.length; i++)
field[i].checked = true ;
}
function uncheckAll(field)
{
for (i = 0; i < field.length; i++)
field[i].checked = false ;
}
// End --
Upvotes: 0
Views: 1107
Reputation: 4074
You should probably change your 5th code lines "name"-attribute, because PHP doesn't parse variables in single quotes. It should be
<?php echo "checkbox[$i]"; ?>
or even better
<?php echo sprintf( 'checkbox[%s]', $i ); ?>
Otherwise the name in your HTML-File will in fact be like <input name="checkbox[$i]" type="checkbox" ... />
Upvotes: 6