title: How to create a single function that handles checkbox selection?
body: <p>I'm working on this simple checkbox selection that works just fine when selecting a single row or selecting all the rows. However, I would like to have only one function that handles the checkbox selection. As of right now I have 3 functions called: customer_name_func , customer_lastname_func and customer_email_func. Can someone help me on this please? Here's my code that works just fine:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(document).ready(function() {
  
    $("#checkAll").change(function() {
      $("input:checkbox").prop('checked', $(this).prop("checked"));
      $(customer_name_func);
      $(customer_lastname_func);
      $(customer_email_func);
    });
  
    var customer_name_func = function() {
      if ($("#customer-name-checkbox").is(":checked")) {
        $('#customer-name-inputField').prop('disabled', false);
      } else {
        $('#customer-name-inputField').prop('disabled', 'disabled');
      }
    };
    $(customer_name_func);
    $("#customer-name-checkbox").change(customer_name_func);
  
    var customer_lastname_func = function() {
      if ($("#customer-lastname-checkbox").is(":checked")) {
        $('#customer-lastname-inputField').prop('disabled', false);
      } else {
        $('#customer-lastname-inputField').prop('disabled', 'disabled');
      }
    };
    $(customer_lastname_func);
    $("#customer-lastname-checkbox").change(customer_lastname_func);
  
    var customer_email_func = function() {
      if ($("#customer-email-checkbox").is(":checked")) {
        $('#customer-email-inputField').prop('disabled', false);
      } else {
        $('#customer-email-inputField').prop('disabled', 'disabled');
      }
    };
    $(customer_email_func);
    $("#customer-email-checkbox").change(customer_email_func);
  
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;form&gt;
    &lt;input type="checkbox" id="checkAll" /&gt;Select All
    &lt;br/&gt;
    &lt;input type="checkbox" id="customer-name-checkbox" name="customer-name-checkbox" value="yes"&gt;
    &lt;!---echo php customerName value from WS---&gt;
    &lt;label for="pizza"&gt;Name&amp;nbsp;&amp;nbsp; LastName&amp;nbsp;&amp;nbsp; Phone Number&lt;/label&gt;
    &lt;input type="email" name="name" id="customer-name-inputField" /&gt;
    &lt;br/&gt;
    &lt;br/&gt;
  
    &lt;input type="checkbox" id="customer-lastname-checkbox" name="customer-lastname-checkbox" value="yes"&gt;
    &lt;!---echo php customerLastName value from WS---&gt;
    &lt;label for="pizza"&gt;Name&amp;nbsp;&amp;nbsp; LastName&amp;nbsp;&amp;nbsp; Phone Number&lt;/label&gt;
    &lt;input type="email" name="email" id="customer-lastname-inputField" /&gt;
    &lt;br/&gt;
    &lt;br/&gt;
  
    &lt;input type="checkbox" id="customer-email-checkbox" name="customer-email-checkbox" value="yes"&gt;
    &lt;!---echo php customerPhoneNumber value from WS---&gt;
    &lt;label for="pizza"&gt;Name&amp;nbsp;&amp;nbsp; LastName&amp;nbsp;&amp;nbsp; Phone Number&lt;/label&gt;
    &lt;input type="email" name="email" id="customer-email-inputField" /&gt;
    &lt;br/&gt;
    &lt;br/&gt;
  
    &lt;input type="submit" value="Send" /&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>