title: JavaScript Function to validate checkbox
body: <p>I'm trying to not allow both checkboxes to be checked at the same time. Here is my vanilla JS. I have the function already validating to return true when one is checked and false when neither are checked. Radio boxes are not an option.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function valForm() {
    var both = document.getElementById("cEmail1" &amp; "cPhone1");
    for (var i = 1; i &lt;= 2; i++) {
      if (document.getElementById("cEmail1").checked) {
        return true;
      } else if (document.getElementById("cPhone1").checked) {
        return true;
      } else if (both.checked) {
        return false;
      } else {
        return false;
      }
    }
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form action="http://severien.com/grit/formecho.php" method="post" name="contactUsForm" onsubmit="return valForm()"&gt;
    &lt;span class="box3"&gt;&lt;label for="cEmail" class="l5" &gt;Contact me by email&lt;/label&gt;
    &lt;input class="check1" id="cEmail1" type="checkbox" name="contactbyemail"  /&gt;&lt;/span&gt;
    &lt;span class="box4"&gt;&lt;label for="cPhone" class="l6"&gt;Contact me by phone&lt;/label&gt;
    &lt;input class="check2" id="cPhone1" type="checkbox" name="contactbyphone"  /&gt;&lt;/span&gt; &lt;br /&gt;
    &lt;div class="formSubmit"&gt;&lt;input type="submit" value="Submit" /&gt;&lt;/div&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>