JavaScript/Multi-selection

Multiple check boxes in a form can be checked with the help of JavaScript. The interface of the demonstration has buttons for each selection method: "Select all", "Select none", and "Invert selection", which are self-explanatory. In addition, there is "Select range", which selects the range between the first and last checked box, and "Zebra select", which alternately selects ranges of check boxes. This means that if the boxes 2, 6, 10, and 14 are checked, the boxes 2 to 6 and 10 to 14 will be selected, and 7, 8, and 9 are not selected.

A range of boxes can also be selected by holding ↑ Shift and clicking on a box.

The code below contains the selection algorithms, referred to by their function names.