JSFiddle - React, Tailwind, and code Playground

HTML

<p>
  Check this checkbox:
</p>

<input type="checkbox" id="checkbox1" name="checkbox" onchange="action()" />

JavaScript

var cb = document.getElementById("checkbox1");
function action() {
		if( cb.checked === true)
    {
    	if( confirm ( "Are you sure 1?") === false )
      {
      	cb.checked = false;
      }    
    }
		else if( cb.checked === false)
    {
    	if( confirm ( "Are you sure 2?") === false )
      {
      	cb.checked = true;
      }
    }
    
  }