A mouse event should call one of two functions, depending on the condition flag = 0, or flag = 1. How to redefine the flag variable, so that one or the other function would work, depending on the value of this variable. Tried it in many different ways. Nothing comes out.
<script type="text/javascript"> flag=0; window.onload = function() { canvas = document.getElementById("Canva"); context = canvas.getContext("2d"); canvas.onmousedown = show; if(flag == 0) { canvas.onmousdown = show;} else if(flag == 1) {canvas.onmousdown = show2;} } function show() { alert('Next'); } function show2() { alert('Stop'); } </script> You can set if else and in the condition of calling the alerts in the function itself. But the essence does not change, the override variable flag does not work out.