Selecting/deselecting checkboxes

Giganews Newsgroups
Subject: Selecting/deselecting checkboxes
Posted by:  jez.hailwo… (Jez)
Date: 17 Jul 2003


I have created the following functions to select and deselect
checkboxes in a form ...

function check(checkbox) {
  for (i = 0; i < checkbox.length; i++) {
    checkbox[i].checked = true;
  return "Select all";

function uncheck(checkbox) {
  for (i = 0; i < checkbox.length; i++) {
    checkbox[i].checked = false;
  return "Select none";

The form itself looks like this ...

<form name="form" action="delete.php" method="post">
  <input type="checkbox" name="id" value="1" />Option 1<br />
  <input type="checkbox" name="id" value="2" />Option 2<br />
  <input type="checkbox" name="id" value="3" />Option 3<br />
  <input type="button" value="Select all"
onClick="this.value=check(" />
  <input type="button" value="Select none"
onClick="this.value=uncheck(" />
  <input type="submit" name="submit" value="Delete selected" />

This all seems to work very well (although constructive critisism
would be welcome), however I actually need to name the input 'id[]'
because I'm generating an array of values. Unfortunately the funtions
don't seem to like '[]'. Is there anything I can do?

Thank you in advance for your help. It's greatly appreciated!