I am studying JavaScript and test a function that I thought could prevent the checkbox from be checked (code sample):
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript" charset="utf-8">
var myBox = document.getElementById('bike');
myBox.addEventListener('click', stopCheck, false);
function stopCheck(e){
e.preventDefault();
}
</script>
<form action="">
<input type="checkbox" name="vehicle" value="Bike" id="bike" >I have a bike<br>
<input type="checkbox" name="vehicle" value="Car">I have a car
</form>
</body>
</html>
but the code does not work. Probably stopCheck is executed AFTER the checkbox changes the checked state. How to fix it?