JSFiddle - React, Tailwind, and code Playground
by Stephen
HTML
<div>
Instructions, other controls, whatever
</div>
<div>
<label for="box1">Box 1</label>
<input type="checkbox" id="box1" name="box1">
<label for="box2">Box 2</label>
<input type="checkbox" id="box2" name="box2">
</div>
<div>
More stuff following the checkboxes
</div>
JavaScript
$('input[type=checkbox]').on('change', function(e) {
console.log('\nchanged: ' + this.name + ' is checked: ' + this.checked);
let allChecked = $('input[type=checkbox]:checked');
console.log('number of boxes checked: ' + allChecked.length)
//$('input[type=checkbox]').not(this).prop('checked', false);
let nowChecked = $('input[type=checkbox]:checked');
if (nowChecked.length === 1) {
console.log("Run the rest of the code; here, or call a function")
}
});