Checked Items Count

Validates # of checked items in table before proceeding

by Chance Nursey-Bush

HTML

<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<body>
  <table>
    <tr>
      <th></th>
      <th>Month</th>
      <th>Savings</th>
    </tr>
    <tr>
      <td>
        <input type="checkbox" />
      </td>
      <td>January</td>
      <td>$100</td>
    </tr>
    <tr>
      <td>
        <input type="checkbox" />
      </td>
      <td>February</td>
      <td>$80</td>
    </tr>
  </table>
  <button id="myButton">Proceed</button>
</body>

CSS

table,
th,
td {
  border: 1px solid black;
}

div {
  color: red;
}

JavaScript

$(document).ready(function() {
  function proceed() {
    var count = $("input:checked").length;
    if (count > 0) {
      alert("you may proceed");
    } else {
      alert("you may not proceed");
    }
  }

  $('#myButton').click(proceed);
});