Select Column

Select all in column when top is checked.

by Puddster

HTML

<table>
    <tr>
        <th> <strong>
                Name
            </strong>

        </th>
        <th>One</th>
        <th>Two</th>
        <th>Three</th>
        <th>Four</th>
    </tr>
    <tr>
        <td>Select All</td>
        <td></td>
        <td>
            <input id="allOffering" type="checkbox" />
        </td>
        <td>
            <input id="allProject" type="checkbox" />
        </td>
        <td>
            <input id="allPastOffering" type="checkbox" />
        </td>
    </tr>
    <tr>
        <td>A</td>
        <td>
            <input type="checkbox" />
        </td>
        <td>
            <input type="checkbox" />
        </td>
        <td>
            <input type="checkbox" />
        </td>
        <td>
            <input type="checkbox" />
        </td>
    </tr>
    <tr>
        <td>B</td>
        <td>
            <input type="checkbox" />
        </td>
        <td>
            <input type="checkbox" />
        </td>
        <td>
            <input type="checkbox" />
        </td>
        <td>
            <input type="checkbox" />
        </td>
    </tr>
    <tr>
        <td>C</td>
        <td>
            <input type="checkbox" />
        </td>
        <td>
            <input type="checkbox" />
        </td>
        <td>
            <input type="checkbox" />
        </td>
        <td>
            <input type="checkbox" />
        </td>
    </tr>
    <tr>
        <td>D</td>
        <td>
            <input type="checkbox" />
        </td>
        <td>
            <input type="checkbox" />
        </td>
        <td>
            <input type="checkbox" />
        </td>
        <td>
            <input type="checkbox" />
        </td>
    </tr>
    <tr>
        <td>E</td>
        <td>
            <input type="checkbox" />
        </td>
        <td>
            <input type="checkbox" />
        </td>
        <td>
            <input type="checkbox" />
        </td>
        <td>
            <input type="checkbox" />
        </td>
   ...

JavaScript

$("input:checkbox").click(function () {
    if ($(this).is(":checked")) {
        $(this).parents("tr").find("input").prop("checked", false);
        $(this).prop("checked", true);
    }
});

$("#allOffering").click(function () {
    $(this).parents("table").find("tr").slice(2, -1).each(function () {
        $(this).find("input").prop("checked", false).eq(1).prop("checked", true);
    });
});

$("#allProject").click(function () {
    $(this).parents("table").find("tr").slice(2, -1).each(function () {
        $(this).find("input").prop("checked", false).eq(2).prop("checked", true);
    });
});

$("#allPastOffering").click(function () {
    $(this).parents("table").find("tr").slice(2, -1).each(function () {
        $(this).find("input").prop("checked", false).eq(3).prop("checked", true);
    });
});

$("#sendAllToPast").click(function () {
    $(this).parents("table").find("tr").slice(2, -1).each(function () {
        if ($(this).find("input").eq(2).is(":checked")) {

        } else {
            $(this).find("input").prop("checked", false).eq(3).prop("checked", true);
        }
    });
});