JSFiddle - React, Tailwind, and code Playground

by chriscoyier

HTML

<form>
  <p>
    <input type="checkbox" id="cb1" onclick="ts(this)">
    <label for="cb1">1st Checkbox</label>
  </p>
  <p>
    <input type="checkbox" id="cb2" checked="checked" onclick="ts(this)">
    <label for="cb2">2nd Checkbox</label>
  </p>
</form>

JavaScript

/* fork from code sent to me by "Casual Trash" */

function ts(cb) {
  if (cb.readOnly) cb.checked=cb.readOnly=false;
  else if (!cb.checked) cb.readOnly=cb.indeterminate=true;
}