简体   繁体   中英

multi checkbox that can check all and uncheck all

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>&nbsp;</td>
      </tr>
      <?php } while ($row_RsActivitynoteMem = mysql_fetch_assoc($RsActivitynoteMem)); ?>
<tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td width="20">&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</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 --

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" ... />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM