JavaScript: Siklus melalui status centang tiga negara bagian

HTML:
<!-- Inline click handler, just for demo -->
<input type="checkbox" id="cb1" onclick="ts(this)">

JS: 
function ts(cb) { // This should show the states in the following order and cycle through them: checked, indeterminate, off.
  if (cb.readOnly) cb.checked=cb.readOnly=false;
  else if (!cb.checked) cb.readOnly=cb.indeterminate=true;
}
Stehlampe2020