我有一个带有多个复选框的表单。为了提高用户体验,我想创建一个全选和取消全选的框。我尝试了很多从互联网上得到的代码,但是它们都无法正常工作。你能否帮我看一下,并告诉我问题出在哪里。谢谢。
<script type="text/javascript">
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 ;
}
</script>
<style type="text/css">
#user_info {
border-collapse:collapse;
}
#user_info td, #user_info th {
width:100px;
border:1px solid #CACACA;
padding:5px;
}
#checkbox{
padding:20px 0 20px 250px;
}
</style>
<p>Please choose all the users whose group_id you want to replace with that of the uploaded file</p>
<form id="groupImportForm" action="<?php echo url_for('group_utilization/importGroupMarching') ?>" method="POST">
<table id="user_info">
<thead>
<th>User ID</th>
<th>Last Name</th>
<th>First Name</th>
<th>Date_Of_Birth</th>
<th>Old Group_ID</th>
<th>New Group_ID</th>
<th>Update GroupID</th>
</thead>
<tbody>
<?php foreach($userGroupData as $value): ?>
<tr>
<td><?php echo $value['user_id']; ?></td>
<td><?php echo $value['last_name']; ?></td>
<td><?php echo $value['first_name']; ?></td>
<td><?php echo $value['date_of_birth']; ?></td>
<td><?php echo $value['group_id_old']; ?></td>
<td><?php echo !empty($value['group_id_new']) ? $value['group_id_new'] : ''; ?></td>
<td><input type="checkbox" name="isReplaceGroupID[<?php echo $value['user_id']; ?>]" value="<?php echo $value['group_id_new']; ?>"></input></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div id="checkbox">
<input type="button" name="CheckAll" value="Check All"
onClick="checkAll(document.myform.list)">
<input type="button" name="UnCheckAll" value="Uncheck All"
onClick="uncheckAll(document.myform.list)">
</div>
<div><input type="submit" value="Continue" /></div>
</form>
<br/>
<br/>