Matrix of checkboxes - only 1 allowed in a row Task
Create a matrix of checkboxes. The user must be able to select only 1 checkbox in a row or unselect all of them.

Solution
&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html;charset=utf-8&quot; &gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
      function switch_checkbox(id_selected, id_pair)
      {
           //if the current checkbox is checked - uncheck the 2-nd checkbox in this row
          if(document.getElementById(id_selected).checked == true)
          {
              document.getElementById(id_pair).checked = false;
          }
      }
    &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;form method=&quot;post&quot; id=&quot;&quot; action=&quot;send.php&quot;&gt;
      &lt;input type=&quot;checkbox&quot; name=&quot;group1[]&quot; id=&quot;1-1&quot; value=&quot;1-1&quot; onChange=&quot;switch_checkbox('1-1', '1-2');&quot;/&gt;
      &lt;input type=&quot;checkbox&quot; name=&quot;group2[]&quot; id=&quot;1-2&quot; value=&quot;1-2&quot; onChange=&quot;switch_checkbox('1-2', '1-1');&quot;/&gt;
      &lt;br /&gt;
      &lt;input type=&quot;checkbox&quot; name=&quot;group1[]&quot; id=&quot;2-1&quot; value=&quot;2-1&quot; onChange=&quot;switch_checkbox('2-1', '2-2');&quot;/&gt;
      &lt;input type=&quot;checkbox&quot; name=&quot;group2[]&quot; id=&quot;2-2&quot; value=&quot;2-2&quot; onChange=&quot;switch_checkbox('2-2', '2-1');&quot;/&gt;
    &lt;/form&gt;
  &lt;/body&gt;
&lt;/html&gt;

As you see, the solution is very primitive. Is it possible to make it even simpler?
Assuming an unchecked starting condition you can eliminate a parameter and thus drop the conditional:

function switch_checkbox(id_pair)
{
    document.getElementById(id_pair).checked = false;
}


...

&lt;input type="checkbox" name="group1[]" id="1-1" value="1-1" onChange="switch_checkbox('1-2');"/&gt;