Drakken Saer Drakken Saer - 5 months ago 7
jQuery Question

Select Multiple Checkboxes By Cntrl + Click

I have a form which has many checkbox elements lined up in rows. I would like to implement a function that allows a user to hold Cntrl, then select a checkbox and have every box either:

A) Become checked is there is no initial box checked

B) Become checked from the closest checked box

Is this possible? Many thanks.


this could help you .

The code is for shift+key

// Usage: $form.find('input[type="checkbox"]').shiftSelectable();
// replace input[type="checkbox"] with the selector to match your list of checkboxes

$.fn.shiftSelectable = function() {
var lastChecked,
    $boxes = this;

$boxes.click(function(evt) {
    if(!lastChecked) {
        lastChecked = this;

    if(evt.shiftKey) {
        var start = $boxes.index(this),
            end = $boxes.index(lastChecked);
        $boxes.slice(Math.min(start, end), Math.max(start, end) + 1)
            .attr('checked', lastChecked.checked)

    lastChecked = this;


credits : jQuery plugin for shift + click to select multiple checkboxes